Skip to content

Commit

Permalink
Added support for urls that have commas
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Nov 29, 2020
1 parent bad7fd1 commit 50a5580
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
singleLineRegExp = regexp.MustCompile(`(\r)|(\n)|(\t)|(\v)|(\f)`) // Carriage returns, line feeds, tabs, for single line transition
timeRegExp = regexp.MustCompile(`[^0-9:]`) // Time allowed characters
uriRegExp = regexp.MustCompile(`[^a-zA-Z0-9-_/?&=#%]`) // URI allowed characters
urlRegExp = regexp.MustCompile(`[^a-zA-Z0-9-_/:.?&@=#%]`) // URL allowed characters
urlRegExp = regexp.MustCompile(`[^a-zA-Z0-9-_/:.,?&@=#%]`) // URL allowed characters
)

// emptySpace is an empty space for replacing
Expand Down
18 changes: 11 additions & 7 deletions sanitize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,19 +799,23 @@ func TestURL(t *testing.T) {
t.Parallel()

var tests = []struct {
name string
input string
expected string
}{
{"Test?=what! &this=that#works", "Test?=what&this=that#works"},
{"/this/test?param$", "/this/test?param"},
{"https://medium.com/@username/some-title-that-is-a-article", "https://medium.com/@username/some-title-that-is-a-article"},
{"https://domain.com/this/test?param$!@()[]{}'<>", "https://domain.com/this/test?param@"},
{"https://domain.com/this/test?this=value&another=123%#page", "https://domain.com/this/test?this=value&another=123%#page"},
{"remove spaces", "Test?=what! &this=that#works", "Test?=what&this=that#works"},
{"no dollar signs", "/this/test?param$", "/this/test?param"},
{"using at sign", "https://medium.com/@username/some-title-that-is-a-article", "https://medium.com/@username/some-title-that-is-a-article"},
{"removing symbols", "https://domain.com/this/test?param$!@()[]{}'<>", "https://domain.com/this/test?param@"},
{"params and anchors", "https://domain.com/this/test?this=value&another=123%#page", "https://domain.com/this/test?this=value&another=123%#page"},
{"allow commas", "https://domain.com/this/test,this,value", "https://domain.com/this/test,this,value"},
}

for _, test := range tests {
output := URL(test.input)
assert.Equal(t, test.expected, output)
t.Run(test.name, func(t *testing.T) {
output := URL(test.input)
assert.Equal(t, test.expected, output)
})
}
}

Expand Down

0 comments on commit 50a5580

Please sign in to comment.