-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
58 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,5 +44,4 @@ func SitemapXml(urlPrefix string) ([]byte, error) { | |
} | ||
|
||
return xml.MarshalIndent(urlset, "", " ") | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package monke | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSanitizeUrl(t *testing.T) { | ||
testData := map[string]string{ | ||
"": "", // empty string stays empty | ||
"a": "/a", // path becomes absolute | ||
"a/": "/a/", // path becomes absolute | ||
"/": "/", // root stays root | ||
"/root": "/root", // path stays path | ||
"/root/": "/root/", // trailing slash is preserved | ||
"/root/../other": "/other", // relative paths are resolved | ||
"/root/../../other": "/other", // relative paths are resolved | ||
"/🤡": "/%F0%9F%A4%A1", // funny symbols are encoded | ||
"/%F0%9F%A4%A1": "/%F0%9F%A4%A1", // encoded paths are preserved | ||
"/path?query": "/path?query", // query is preserved | ||
"/path/?query": "/path/?query", // query is preserved | ||
"/path/?param=/path/": "/path/?param=/path/", // query is preserved | ||
"/path/?param=/path/../../../": "/path/?param=/path/../../../", // query is preserved | ||
} | ||
for s, want := range testData { | ||
got := SanitizeUrl(s) | ||
if got != want { | ||
t.Fatalf("Failed to sanitize %s: expected %s, got %s", s, want, got) | ||
} | ||
} | ||
} |