From b1a8d765527f785e14e69b791c25fa402cb23d47 Mon Sep 17 00:00:00 2001 From: Kory Prince Date: Tue, 21 Jan 2025 17:54:22 -0600 Subject: [PATCH] ignore comments in XML plist files (#45) Co-authored-by: Kory Prince --- testdata/xml/comment.plist | 21 +++++++++++++++++++++ xml_parser.go | 13 +++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 testdata/xml/comment.plist diff --git a/testdata/xml/comment.plist b/testdata/xml/comment.plist new file mode 100644 index 0000000..f45f44f --- /dev/null +++ b/testdata/xml/comment.plist @@ -0,0 +1,21 @@ + + + + + + + + + key + + val + + key2 + + + val1 + val2 + + + + diff --git a/xml_parser.go b/xml_parser.go index 375d680..7505403 100644 --- a/xml_parser.go +++ b/xml_parser.go @@ -17,6 +17,19 @@ type xmlParser struct { *xml.Decoder } +func (p *xmlParser) Token() (xml.Token, error) { + for { + token, err := p.Decoder.Token() + if err != nil { + return nil, err + } + if _, ok := token.(xml.Comment); ok { + continue + } + return token, nil + } +} + // newXMLParser returns a new xmlParser func newXMLParser(r io.Reader) *xmlParser { return &xmlParser{xml.NewDecoder(r)}