Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
a11b748f
Commit
a11b748f
authored
Aug 31, 2012
by
Shawn Smith
Committed by
Russ Cox
Aug 31, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
encoding/xml: parse comments in DOCTYPE
R=rsc, n13m3y3r CC=golang-dev
https://golang.org/cl/6330061
parent
2785f952
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
1 deletion
+63
-1
src/pkg/encoding/xml/xml.go
src/pkg/encoding/xml/xml.go
+30
-1
src/pkg/encoding/xml/xml_test.go
src/pkg/encoding/xml/xml_test.go
+33
-0
No files found.
src/pkg/encoding/xml/xml.go
View file @
a11b748f
...
...
@@ -584,6 +584,7 @@ func (d *Decoder) RawToken() (Token, error) {
if
inquote
==
0
&&
b
==
'>'
&&
depth
==
0
{
break
}
HandleB
:
d
.
buf
.
WriteByte
(
b
)
switch
{
case
b
==
inquote
:
...
...
@@ -599,7 +600,35 @@ func (d *Decoder) RawToken() (Token, error) {
depth
--
case
b
==
'<'
&&
inquote
==
0
:
depth
++
// Look for <!-- to begin comment.
s
:=
"!--"
for
i
:=
0
;
i
<
len
(
s
);
i
++
{
if
b
,
ok
=
d
.
mustgetc
();
!
ok
{
return
nil
,
d
.
err
}
if
b
!=
s
[
i
]
{
for
j
:=
0
;
j
<
i
;
j
++
{
d
.
buf
.
WriteByte
(
s
[
j
])
}
depth
++
goto
HandleB
}
}
// Remove < that was written above.
d
.
buf
.
Truncate
(
d
.
buf
.
Len
()
-
1
)
// Look for terminator.
var
b0
,
b1
byte
for
{
if
b
,
ok
=
d
.
mustgetc
();
!
ok
{
return
nil
,
d
.
err
}
if
b0
==
'-'
&&
b1
==
'-'
&&
b
==
'>'
{
break
}
b0
,
b1
=
b1
,
b
}
}
}
return
Directive
(
d
.
buf
.
Bytes
()),
nil
...
...
src/pkg/encoding/xml/xml_test.go
View file @
a11b748f
...
...
@@ -621,3 +621,36 @@ func TestProcInstEncoding(t *testing.T) {
}
}
}
// Ensure that directives with comments include the complete
// text of any nested directives.
var
directivesWithCommentsInput
=
`
<!DOCTYPE [<!-- a comment --><!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">]>
<!DOCTYPE [<!ENTITY go "Golang"><!-- a comment-->]>
<!DOCTYPE <!-> <!> <!----> <!-->--> <!--->--> [<!ENTITY go "Golang"><!-- a comment-->]>
`
var
directivesWithCommentsTokens
=
[]
Token
{
CharData
(
"
\n
"
),
Directive
(
`DOCTYPE [<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">]`
),
CharData
(
"
\n
"
),
Directive
(
`DOCTYPE [<!ENTITY go "Golang">]`
),
CharData
(
"
\n
"
),
Directive
(
`DOCTYPE <!-> <!> [<!ENTITY go "Golang">]`
),
CharData
(
"
\n
"
),
}
func
TestDirectivesWithComments
(
t
*
testing
.
T
)
{
d
:=
NewDecoder
(
strings
.
NewReader
(
directivesWithCommentsInput
))
for
i
,
want
:=
range
directivesWithCommentsTokens
{
have
,
err
:=
d
.
Token
()
if
err
!=
nil
{
t
.
Fatalf
(
"token %d: unexpected error: %s"
,
i
,
err
)
}
if
!
reflect
.
DeepEqual
(
have
,
want
)
{
t
.
Errorf
(
"token %d = %#v want %#v"
,
i
,
have
,
want
)
}
}
}
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