1

I have a Go code:

xmlData := `<foo xmlns:="url"/>`
xmlDec := xml.NewDecoder(bytes.NewReader([]byte(xmlData)))
rawToken, _ := xmlDec.RawToken()
fmt.Println(rawToken)

Now interesting part, let's use Go 1.14.0

Output: {{ foo} [{{xmlns } url}]}

Switch to Go 1.18.0

Output: {{ foo} [{{ xmlns:} url}]}

In the first output xml.Name.Space = "xmlns" and xml.Name.Local = ""

In the second output xml.Name.Space = "" and xml.Name.Local = "xmlns:"

Can anybody explain me what is going on?

kostix
  • 51,517
  • 14
  • 93
  • 176
AnthonyGP
  • 47
  • 2
  • 4
    `` is not a correct namespace. Either don't use a `:` (``) or define prefix for a namespace (``) – Siebe Jongebloed Aug 10 '23 at 12:22
  • @SiebeJongebloed indeed, the idea was to have the same output as Go 1.14. Then the `xml.Name.Local` = `"xmlns:"` is also invalid! But as you see it is parsed in Go 1.18. Not sure that the case only in xml invalidity – AnthonyGP Aug 10 '23 at 12:42
  • I would suggest that both versions should have raised an error at line 2 – Siebe Jongebloed Aug 10 '23 at 12:46
  • 1
    There were a bunch of xml bug fixes over the course of those releases, have you checked if any apply to namespace handling? – JimB Aug 10 '23 at 14:04
  • @JimB even if they were, why invalid xml still being parsed, that's what I'm concerned about. Go 1.14 could parse "xmlns:" as `namespace=xmlns"` and `tag=""`, why would then Go 1.18 parse that as `namespace=""` and `tag="xmlns:"`. If you say "bug fixes" then it should be already fixed and report an error, but it doesnt ;) – AnthonyGP Aug 10 '23 at 14:16
  • @SiebeJongebloed it should raise, if we talk about correctness of XML, but in fact, Go 1.18 doesnt raise that. And even more, Go 1.14 still parses that in more correct way than Go 1.18 (even if both are false) – AnthonyGP Aug 10 '23 at 14:18
  • 1
    I don't know, just trying to point you to some clues about where the behavior might have changed. I recall something about namespaces, but it's been a couple years. – JimB Aug 10 '23 at 14:18
  • @JimB seems that I found that commit, so try to figure out how to fix it on my end, but not sure :/, thanks anyway for the support – AnthonyGP Aug 10 '23 at 14:27

0 Answers0