diff --git a/src/encoding/xml/xml.go b/src/encoding/xml/xml.go index 0fe323f7c86..5da24544a04 100644 --- a/src/encoding/xml/xml.go +++ b/src/encoding/xml/xml.go @@ -604,27 +604,45 @@ func (d *Decoder) rawToken() (Token, error) { case '?': // ' { + 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)