Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
6c204982
Commit
6c204982
authored
Jun 08, 2012
by
Nigel Tao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
exp/html: check the context node for consistency when parsing fragments.
R=rsc CC=golang-dev
https://golang.org/cl/6303053
parent
072e36d5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
parse.go
src/pkg/exp/html/parse.go
+11
-0
parse_test.go
src/pkg/exp/html/parse_test.go
+13
-0
No files found.
src/pkg/exp/html/parse.go
View file @
6c204982
...
@@ -5,7 +5,9 @@
...
@@ -5,7 +5,9 @@
package
html
package
html
import
(
import
(
"errors"
a
"exp/html/atom"
a
"exp/html/atom"
"fmt"
"io"
"io"
"strings"
"strings"
)
)
...
@@ -2013,6 +2015,15 @@ func ParseFragment(r io.Reader, context *Node) ([]*Node, error) {
...
@@ -2013,6 +2015,15 @@ func ParseFragment(r io.Reader, context *Node) ([]*Node, error) {
}
}
if
context
!=
nil
{
if
context
!=
nil
{
if
context
.
Type
!=
ElementNode
{
return
nil
,
errors
.
New
(
"html: ParseFragment of non-element Node"
)
}
// The next check isn't just context.DataAtom.String() == context.Data because
// it is valid to pass an element whose tag isn't a known atom. For example,
// DataAtom == 0 and Data = "tagfromthefuture" is perfectly consistent.
if
context
.
DataAtom
!=
a
.
Lookup
([]
byte
(
context
.
Data
))
{
return
nil
,
fmt
.
Errorf
(
"html: inconsistent Node: DataAtom=%q, Data=%q"
,
context
.
DataAtom
,
context
.
Data
)
}
switch
context
.
DataAtom
{
switch
context
.
DataAtom
{
case
a
.
Iframe
,
a
.
Noembed
,
a
.
Noframes
,
a
.
Noscript
,
a
.
Plaintext
,
a
.
Script
,
a
.
Style
,
a
.
Title
,
a
.
Textarea
,
a
.
Xmp
:
case
a
.
Iframe
,
a
.
Noembed
,
a
.
Noframes
,
a
.
Noscript
,
a
.
Plaintext
,
a
.
Script
,
a
.
Style
,
a
.
Title
,
a
.
Textarea
,
a
.
Xmp
:
p
.
tokenizer
.
rawTag
=
context
.
DataAtom
.
String
()
p
.
tokenizer
.
rawTag
=
context
.
DataAtom
.
String
()
...
...
src/pkg/exp/html/parse_test.go
View file @
6c204982
...
@@ -391,6 +391,19 @@ var renderTestBlacklist = map[string]bool{
...
@@ -391,6 +391,19 @@ var renderTestBlacklist = map[string]bool{
`<table><plaintext><td>`
:
true
,
`<table><plaintext><td>`
:
true
,
}
}
func
TestNodeConsistency
(
t
*
testing
.
T
)
{
// inconsistentNode is a Node whose DataAtom and Data do not agree.
inconsistentNode
:=
&
Node
{
Type
:
ElementNode
,
DataAtom
:
atom
.
Frameset
,
Data
:
"table"
,
}
_
,
err
:=
ParseFragment
(
strings
.
NewReader
(
"<p>hello</p>"
),
inconsistentNode
)
if
err
==
nil
{
t
.
Errorf
(
"got nil error, want non-nil"
)
}
}
func
BenchmarkParser
(
b
*
testing
.
B
)
{
func
BenchmarkParser
(
b
*
testing
.
B
)
{
buf
,
err
:=
ioutil
.
ReadFile
(
"testdata/go1.html"
)
buf
,
err
:=
ioutil
.
ReadFile
(
"testdata/go1.html"
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment