diff options
author | ZhangYunHao <zhangyunhao116@gmail.com> | 2022-03-15 16:39:40 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-15 09:39:40 +0100 |
commit | f7423e3def0565dc581debc6549601b613f34fa9 (patch) | |
tree | a418908a7992b0d403a5b00d830cc06eb3b0063c /bytesconv_test.go | |
parent | Read response when client closes connection #1232 (#1233) (diff) | |
download | fasthttp-f7423e3def0565dc581debc6549601b613f34fa9.tar.gz fasthttp-f7423e3def0565dc581debc6549601b613f34fa9.tar.bz2 fasthttp-f7423e3def0565dc581debc6549601b613f34fa9.zip |
Fix AppendHTMLEscape (#1248)
Diffstat (limited to 'bytesconv_test.go')
-rw-r--r-- | bytesconv_test.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/bytesconv_test.go b/bytesconv_test.go index 4c35371..297b4a1 100644 --- a/bytesconv_test.go +++ b/bytesconv_test.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "fmt" + "html" "net" "testing" "time" @@ -14,10 +15,21 @@ import ( func TestAppendHTMLEscape(t *testing.T) { t.Parallel() + // Sync with html.EscapeString + allcases := make([]byte, 256) + for i := 0; i < 256; i++ { + allcases[i] = byte(i) + } + res := string(AppendHTMLEscape(nil, string(allcases))) + expect := string(html.EscapeString(string(allcases))) + if res != expect { + t.Fatalf("unexpected string %q. Expecting %q.", res, expect) + } + testAppendHTMLEscape(t, "", "") testAppendHTMLEscape(t, "<", "<") testAppendHTMLEscape(t, "a", "a") - testAppendHTMLEscape(t, `><"''`, "><"''") + testAppendHTMLEscape(t, `><"''`, "><"''") testAppendHTMLEscape(t, "fo<b x='ss'>a</b>xxx", "fo<b x='ss'>a</b>xxx") } |