Fix parsing of quotes in attribute names #11543
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Quotes in attribute names are allowed by HTML spec. See https://html.spec.whatwg.org/multipage/parsing.html#attribute-name-state. Technically it's a parse error but the quote is still considered part of the attribute name and that's important here.
Previously, if razor saw a quote at the beginning of attribute name context, it would bail and consume everything until the matching quote. That's not how browsers parse that HTML - they consume the quote as part of the attribute name (and don't look for a matching quote). So this PR changes razor parser to do the same.
This fixes #11327 - the rest of the html after the misplaced quote is not stuffed into a "misc attribute" node as previously, but just the misplaced quote is parsed as an html attribute and then parsing continues normally, i.e., subsequent HTML elements are normally recognized, and tag helpers have effect on them, etc.
Visually:
No error is reported for the attribute named
"
. It looks like razor doesn't usually report errors for invalid HTML (especially such that browsers handle gracefully like here).