From aed0bc8b5d935c74472b2035e96a1671752814bf Mon Sep 17 00:00:00 2001 From: David Kitchen Date: Fri, 23 Apr 2021 08:47:03 +0100 Subject: [PATCH] Add test for quotes to prevent regression on the ASCII SCRIPT issue --- sanitize_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/sanitize_test.go b/sanitize_test.go index a6aa3d9..1bb45a9 100644 --- a/sanitize_test.go +++ b/sanitize_test.go @@ -1795,3 +1795,43 @@ func TestIssue111ScriptTags(t *testing.T) { ) } } + +func TestQuotes(t *testing.T) { + p := UGCPolicy() + + tests := []test{ + { + in: `noquotes`, + expected: `noquotes`, + }, + { + in: `"singlequotes"`, + expected: `"singlequotes"`, + }, + { + in: `""doublequotes""`, + expected: `""doublequotes""`, + }, + } + + // These tests are run concurrently to enable the race detector to pick up + // potential issues + wg := sync.WaitGroup{} + wg.Add(len(tests)) + for ii, tt := range tests { + go func(ii int, tt test) { + out := p.Sanitize(tt.in) + if out != tt.expected { + t.Errorf( + "test %d failed;\ninput : %s\noutput : %s\nexpected: %s", + ii, + tt.in, + out, + tt.expected, + ) + } + wg.Done() + }(ii, tt) + } + wg.Wait() +}