Skip to content

Conversation

@cwarden
Copy link
Contributor

@cwarden cwarden commented Oct 8, 2025

No description provided.

@cwarden cwarden mentioned this pull request Oct 8, 2025
@case-fastly
Copy link
Contributor

Thanks @cwarden! Apologies for the delay in replying here - we'll have a look asap.

Copy link

@Integralist Integralist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change and tests look fine, I ran the tests locally without removing the offending code from xml.go and I could see the test correctly validates we timeout when parsing a multiline input that contains a > in the tag value.

I've approved the PR but the question becomes: how do we want to deal with the scenario that the code was originally trying to handle?

Looks like the original code was trying to catch something like the following (potentially in non-strict mode?):

<tag attr=value > with > symbols></tag>

I wrote a quick program to check the output.

With the change from this PR we get the following (which seems fine to me), otherwise we get infinite loop.

So I think we're fine to merge.

Parsing: <tag foo=bar attr=value > with > symbols beep=boop></tag>

StartElement: name="tag"
  Attribute: "foo" = "bar"
  Attribute: "attr" = "value"
CharData: " with > symbols beep=boop>"
EndElement: name="tag"
package main

import (
	"fmt"
	"io"
	"strings"

	xml "github.com/nbio/xml"
)

func main() {
	input := `<tag foo=bar attr=value > with > symbols beep=boop></tag>`
	d := xml.NewDecoder(strings.NewReader(input))
	d.Strict = false

	fmt.Println("Parsing:", input)
	fmt.Println()

	for {
		tok, err := d.Token()
		if err == io.EOF {
			break
		}
		if err != nil {
			fmt.Printf("Error: %v\n", err)
			break
		}

		switch t := tok.(type) {
		case xml.StartElement:
			fmt.Printf("StartElement: name=%q\n", t.Name.Local)
			for _, attr := range t.Attr {
				fmt.Printf("  Attribute: %q = %q\n", attr.Name.Local, attr.Value)
			}
		case xml.CharData:
			fmt.Printf("CharData: %q\n", string(t))
		case xml.EndElement:
			fmt.Printf("EndElement: name=%q\n", t.Name.Local)
		}
	}
}

@Integralist Integralist merged commit a619c11 into nbio:main Oct 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants