From eff32f573b19b83283785c1df4539232c39fdba0 Mon Sep 17 00:00:00 2001 From: Andrew Balholm Date: Sun, 29 Jul 2012 16:29:49 +1000 Subject: [PATCH] exp/html: replace NUL with U+FFFD in text in foreign content Pass 5 additional tests. R=nigeltao CC=golang-dev https://golang.org/cl/6452055 --- src/pkg/exp/html/parse.go | 6 ++++-- src/pkg/exp/html/testlogs/plain-text-unsafe.dat.log | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/pkg/exp/html/parse.go b/src/pkg/exp/html/parse.go index 986e9bbe46..38e61677e3 100644 --- a/src/pkg/exp/html/parse.go +++ b/src/pkg/exp/html/parse.go @@ -1846,14 +1846,16 @@ func afterAfterFramesetIM(p *parser) bool { return true } +const whitespaceOrNUL = whitespace + "\x00" + // Section 12.2.5.5. func parseForeignContent(p *parser) bool { switch p.tok.Type { case TextToken: - p.tok.Data = strings.Replace(p.tok.Data, "\x00", "", -1) if p.framesetOK { - p.framesetOK = strings.TrimLeft(p.tok.Data, whitespace) == "" + p.framesetOK = strings.TrimLeft(p.tok.Data, whitespaceOrNUL) == "" } + p.tok.Data = strings.Replace(p.tok.Data, "\x00", "\ufffd", -1) p.addText(p.tok.Data) case CommentToken: p.addChild(&Node{ diff --git a/src/pkg/exp/html/testlogs/plain-text-unsafe.dat.log b/src/pkg/exp/html/testlogs/plain-text-unsafe.dat.log index b63a237a15..f2d18d4711 100644 --- a/src/pkg/exp/html/testlogs/plain-text-unsafe.dat.log +++ b/src/pkg/exp/html/testlogs/plain-text-unsafe.dat.log @@ -12,13 +12,13 @@ PASS "\x00filler\x00text\x00" PASS "" PASS "" PASS "\x00filler\x00text" -FAIL "\x00filler\x00text" -FAIL "\x00" -FAIL "\x00 " -FAIL "\x00a" +PASS "\x00filler\x00text" +PASS "\x00" +PASS "\x00 " +PASS "\x00a" PASS "\x00" PASS "\x00 " -FAIL "\x00a" +PASS "\x00a" PASS "" PASS "

" PASS "

\r\n\r\nA
" -- 2.48.1