diff options
| author | Andrew Balholm <andybalholm@gmail.com> | 2011-11-22 09:27:27 +1100 |
|---|---|---|
| committer | Nigel Tao <nigeltao@golang.org> | 2011-11-22 09:27:27 +1100 |
| commit | 750de28d6ceb5c42637b08fb87f2de2f826ed0eb (patch) | |
| tree | 1ef8d7aad26e9f4f5a284914f3c7221fb03d29ae /src/pkg/html/parse.go | |
| parent | 86c08e961136f01d34db7759166433d55e8914b2 (diff) | |
| download | go-750de28d6ceb5c42637b08fb87f2de2f826ed0eb.tar.xz | |
html: ignore whitespace before <head> element
Pass tests2.dat, test 47:
" \n "
(That is, two spaces separated by a newline)
| <html>
| <head>
| <body>
Also pass tests through test 49:
<!DOCTYPE html><script>
</script> <title>x</title> </head>
R=nigeltao
CC=golang-dev
https://golang.org/cl/5422043
Diffstat (limited to 'src/pkg/html/parse.go')
| -rw-r--r-- | src/pkg/html/parse.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/pkg/html/parse.go b/src/pkg/html/parse.go index 9b7e934ac3..b74831b34e 100644 --- a/src/pkg/html/parse.go +++ b/src/pkg/html/parse.go @@ -319,9 +319,17 @@ func (p *parser) resetInsertionMode() { p.im = inBodyIM } +const whitespace = " \t\r\n\f" + // Section 11.2.5.4.1. func initialIM(p *parser) bool { switch p.tok.Type { + case TextToken: + p.tok.Data = strings.TrimLeft(p.tok.Data, whitespace) + if len(p.tok.Data) == 0 { + // It was all whitespace, so ignore it. + return true + } case CommentToken: p.doc.Add(&Node{ Type: CommentNode, @@ -345,6 +353,12 @@ func initialIM(p *parser) bool { // Section 11.2.5.4.2. func beforeHTMLIM(p *parser) bool { switch p.tok.Type { + case TextToken: + p.tok.Data = strings.TrimLeft(p.tok.Data, whitespace) + if len(p.tok.Data) == 0 { + // It was all whitespace, so ignore it. + return true + } case StartTagToken: if p.tok.Data == "html" { p.addElement(p.tok.Data, p.tok.Attr) @@ -383,7 +397,11 @@ func beforeHeadIM(p *parser) bool { case ErrorToken: implied = true case TextToken: - // TODO: distinguish whitespace text from others. + p.tok.Data = strings.TrimLeft(p.tok.Data, whitespace) + if len(p.tok.Data) == 0 { + // It was all whitespace, so ignore it. + return true + } implied = true case StartTagToken: switch p.tok.Data { @@ -417,8 +435,6 @@ func beforeHeadIM(p *parser) bool { return !implied } -const whitespace = " \t\r\n\f" - // Section 11.2.5.4.4. func inHeadIM(p *parser) bool { var ( |
