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: unmarshaller and whitespace #22146
Comments
According to the git history 1a37656 bools have been trimmed since they were first added by @rsc. @rsc: What was the motivation for trimming bools? Was it convenience? If the reasoning was convenience I think it makes sense for there to be consistency across types where whitespace has no meaning since consistency will result in less wrong assumptions, but I think if it was to be added for consistency it'd need to be added to unsigned ints and floats too. The no error on an invalid integer isn't intuitive and I think it should be considered a bug if trimming isn't introduced. |
Not to weigh on any side of the scales, I'd still point out a bit from my response to @md2perpe over there on the ML:
That is, while " 266703" looks innocent enough, though mildly annoying as it hints at sloppy |
@leighmcculloch Since we don't do our code review on Github it sometimes helps to look over there to get more background on a change. In this case, https://golang.org/cl/218050 . In this case it looks like the purpose of the CL was to accept more strings for bool values. It's not clear that anybody really considered the call to |
Clearly we didn't think much of adding strings.TrimSpace in CL 218050 (which Michael Hoisie wrote and I reviewed), but it seems fine to apply strings.TrimSpace to all those numeric fields. Please make sure to update the docs and add a test. CLs welcome. Thanks. |
If no one else is already on it I'd like to submit a CL to make the change. 🖐️ |
Change https://golang.org/cl/73891 mentions this issue: |
The issue
I had a file with space padded numbers (
NumberOfPoints=" 266703"
) but the XML unmarshaller couldn't handle the spaces.Booleans are trimmed, so why not numbers?
Does this issue reproduce with the latest release?
The issue exists in the currently latest commit in the GitHub repository:
https://github.com/golang/go/blob/99da873/src/encoding/xml/read.go
What operating system and processor architecture are you using (
go env
)?Not relevant as the issue is in architecture-independent library code.
Examples
Good to know
I first asked about this and was given a workaround on Google Groups:
https://groups.google.com/forum/#!topic/golang-nuts/RtKU05cE9PY
The text was updated successfully, but these errors were encountered: