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 "