From 50a5580bc5166ef5c8d636a3a44958e18ef9e19a Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Sun, 29 Nov 2020 17:25:30 -0500 Subject: [PATCH] Added support for urls that have commas --- sanitize.go | 2 +- sanitize_test.go | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/sanitize.go b/sanitize.go index bd647e3..c721d66 100644 --- a/sanitize.go +++ b/sanitize.go @@ -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 diff --git a/sanitize_test.go b/sanitize_test.go index bb48cd1..9fbe92f 100644 --- a/sanitize_test.go +++ b/sanitize_test.go @@ -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) + }) } }