aboutsummaryrefslogtreecommitdiff
path: root/bytesconv_test.go
diff options
context:
space:
mode:
authorGravatar ZhangYunHao <zhangyunhao116@gmail.com> 2022-03-15 16:39:40 +0800
committerGravatar GitHub <noreply@github.com> 2022-03-15 09:39:40 +0100
commitf7423e3def0565dc581debc6549601b613f34fa9 (patch)
treea418908a7992b0d403a5b00d830cc06eb3b0063c /bytesconv_test.go
parentRead response when client closes connection #1232 (#1233) (diff)
downloadfasthttp-f7423e3def0565dc581debc6549601b613f34fa9.tar.gz
fasthttp-f7423e3def0565dc581debc6549601b613f34fa9.tar.bz2
fasthttp-f7423e3def0565dc581debc6549601b613f34fa9.zip
Fix AppendHTMLEscape (#1248)
Diffstat (limited to 'bytesconv_test.go')
-rw-r--r--bytesconv_test.go14
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, "<", "&lt;")
testAppendHTMLEscape(t, "a", "a")
- testAppendHTMLEscape(t, `><"''`, "&gt;&lt;&quot;&#39;&#39;")
+ testAppendHTMLEscape(t, `><"''`, "&gt;&lt;&#34;&#39;&#39;")
testAppendHTMLEscape(t, "fo<b x='ss'>a</b>xxx", "fo&lt;b x=&#39;ss&#39;&gt;a&lt;/b&gt;xxx")
}