-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: accepts ill-formed XML declarations #68460
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Comments
14 tasks
Could you share a code snippet for how you parse the XML? Thanks. |
cherrymui
added
the
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
label
Jul 16, 2024
https://go.dev/play/p/gmZ-M1l8zVp package main
import (
"encoding/xml"
"os"
"fmt"
"strings"
)
func checkIllFormedXMLGetsError(s string) (ok bool) {
var v error
d := xml.NewDecoder(strings.NewReader(s))
d.CharsetReader = func(charset string, reader io.Reader) (io.Reader, error) { return reader, nil }
tok, err := d.RawToken()
if tok != nil || err == nil {
_, v = fmt.Printf("BAD: got a token (%#v) or no error (%#v) when decoding %q\n", tok, err, s)
} else {
_, v = fmt.Printf("GOOD: got error (%#v) on ill-formed XML (%q)\n", err, s)
ok = true
}
if v != nil {
panic(v)
}
return
}
func main() {
illFormedDocs := []string{
`<?xml standalone="yes" version="1.0"?>`,
`<?xml version="1.0"standalone="yes"?>`,
`<?xml version="1.0" a standalone="yes"?>`,
`<?xml version="1.0" dalone="yes"?>`,
`<?xml version="1.0" encoding="not valid"?>`,
`<?xml version="1.0" standalone="not valid"?>`,
}
bad := false
for _, illFormed := range(illFormedDocs) {
if !checkIllFormedXMLGetsError(illFormed) {
bad = true
}
}
if bad {
os.Exit(1)
}
} |
cherrymui
added
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
and removed
WaitingForInfo
Issue is not actionable because of missing required information, which needs to be provided.
labels
Jul 17, 2024
Thanks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
Git main
Output of
go env
in your module/workspace:What did you do?
Tried to parse XML with various ill-formed XML declarations, such as the following:
Wrong order of key/value pairs:
Missing space between key/value pairs:
Junk in data:
Invalid key:
Invalid encoding:
Invalid standalone value
What did you see happen?
No error, so long as a
CharsetReader
that can handle the invalid encoding is provided.What did you expect to see?
Errors because these documents are ill-formed.
The text was updated successfully, but these errors were encountered: