Skip to content

Commit

Permalink
fix(parser): use element name parser to extract name for raw parser
Browse files Browse the repository at this point in the history
In the existing code, if the raw element name is successfully parsed,
it immediately attempts to parse the attributes, without checking
for whitespace or a closing `>`.

This means that something like `<scripts>` would be parsed as a
`<script>` tag with a boolean attribute of `s` (the last character of
the tag name). This would then give a confusing error about mismatched
tags as the closing `</scripts>` tag was actually parsed correctly.

This commit fixes this issue by delegating to the elementNameParser,
which checks for whitespace or a closing `>`, and then compares the
names of the elements.
  • Loading branch information
deej-io committed Apr 25, 2024
1 parent 98cdafa commit b6b71cb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion parser/v2/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ func (p rawElementParser) Parse(pi *parse.Input) (n Node, ok bool, err error) {

// Element name.
var e RawElement
if e.Name, ok, err = parse.String(p.name).Parse(pi); err != nil || !ok {
if e.Name, ok, err = elementNameParser.Parse(pi); err != nil || !ok {
pi.Seek(start)
return
}

if e.Name != p.name {
pi.Seek(start)
ok = false
return
}

if e.Attributes, ok, err = (attributesParser{}).Parse(pi); err != nil || !ok {
pi.Seek(start)
return
Expand Down

0 comments on commit b6b71cb

Please sign in to comment.