Skip to content

Commit

Permalink
ignore comments in XML plist files (#45)
Browse files Browse the repository at this point in the history
Co-authored-by: Kory Prince <[email protected]>
  • Loading branch information
korylprince and Kory Prince authored Jan 21, 2025
1 parent 14eed58 commit b1a8d76
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions testdata/xml/comment.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- comment -->
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- comment -->
<plist version="1.0">
<!-- comment -->
<dict>
<!-- comment -->
<key>key</key>
<!-- comment -->
<string>val</string>
<!-- comment -->
<key>key2</key>
<array>
<!-- comment -->
<string>val1</string>
<string>val2</string>
</array>
</dict>
<!-- comment -->
</plist>
13 changes: 13 additions & 0 deletions xml_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down

0 comments on commit b1a8d76

Please sign in to comment.