This repository was archived by the owner on Mar 10, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed
Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -90,9 +90,7 @@ defmodule Thesis.Controller.Plug do
9090 end
9191
9292 def call ( conn , _opts ) do
93- url = conn . request_path
94- |> String . replace ( ~r/ (?<=[^:])(\/ \/ )/ , conn . request_path , "/" ) # Strip double slashes
95- |> String . replace ( ~r/ \/ $/ , "" ) # Strip trailing slash
93+ url = Thesis.Utilities . normalize_url ( conn . request_path )
9694 current_page = store . page ( url )
9795 page_contents = store . page_contents ( current_page )
9896
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ defmodule Thesis.Utilities do
33 Module that provides helper functions.
44 """
55
6+
67 def parameterize ( str ) do
78 str = Regex . replace ( ~r/ [^a-z0-9\- \s \. ]/ i , str , "" )
89 Regex . split ( ~r/ \% 20|\s / , str )
@@ -18,4 +19,18 @@ defmodule Thesis.Utilities do
1819 |> String . downcase
1920 |> binary_part ( 0 , length )
2021 end
22+
23+ @ doc """
24+ Takes a URL and strips unnecessary characters.
25+
26+ iex> Thesis.Utilities.normalize_url("http://infinite.red//ignite//foo")
27+ "http://infinite.red/ignite/foo"
28+ iex> Thesis.Utilities.normalize_url("https://infinite.red/ignite/foo/")
29+ "https://infinite.red/ignite/foo"
30+ """
31+ def normalize_url ( url ) do
32+ url
33+ |> String . replace ( ~r/ (?<=[^:])(\/ \/ )/ , "/" ) # Strip double slashes
34+ |> String . replace ( ~r/ \/ $/ , "" ) # Strip trailing slash
35+ end
2136end
Original file line number Diff line number Diff line change 1+ defmodule UtilitiesTest do
2+ use ExUnit.Case
3+ doctest Thesis.Utilities
4+ end
You can’t perform that action at this time.
0 commit comments