Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/xml: require whitespace before processing instruction value #69200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions src/encoding/xml/xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,27 +604,45 @@ func (d *Decoder) rawToken() (Token, error) {
case '?':
// <?: Processing instruction.
var target string
var data []byte
if target, ok = d.name(); !ok {
if d.err == nil {
d.err = d.syntaxError("expected target name after <?")
}
return nil, d.err
}
d.space()
d.buf.Reset()
var b0 byte
for {
if b, ok = d.mustgetc(); !ok {
return nil, d.err
}
switch b {
case ' ', '\t', '\r', '\n':
d.space()
var b0 byte
for {
if b, ok = d.mustgetc(); !ok {
return nil, d.err
}
d.buf.WriteByte(b)
if b0 == '?' && b == '>' {
break
}
b0 = b
}
data = d.buf.Bytes()
data = data[0 : len(data)-2] // chop ?>
case '?':
if b, ok = d.mustgetc(); !ok {
return nil, d.err
}
d.buf.WriteByte(b)
if b0 == '?' && b == '>' {
break
if b != '>' {
d.err = d.syntaxError("expected ?> after empty processing instruction")
return nil, d.err
}
b0 = b
default:
d.err = d.syntaxError("unexpected byte after processing instruction name")
return nil, d.err
}
data := d.buf.Bytes()
data = data[0 : len(data)-2] // chop ?>

if target == "xml" {
content := string(data)
Expand Down