fix(compiler-core): error on unexpected first character of an attribute name - #15284
Open
ValentinYoushkevich wants to merge 1 commit into
Open
fix(compiler-core): error on unexpected first character of an attribute name#15284ValentinYoushkevich wants to merge 1 commit into
ValentinYoushkevich wants to merge 1 commit into
Conversation
…te name
Per the HTML spec, `"`, `'` and `<` hitting the attribute name state
trigger the unexpected-character-in-attribute-name parse error, including
when reconsumed as the FIRST character from the before attribute name
state. The tokenizer only reported the error for subsequent characters,
so `<div a<b>` errored while `<div <b>` was silently swallowed as an
attribute named `<b`.
The silent case is how an unclosed tag manifests: in
<div
<span>hi</span>
</div>
the `<span` became an attribute of `div` and the only diagnostic was a
misleading "Invalid end tag." pointing at `</span>`. Now the error is
also reported at the exact position where the new tag opens before the
previous one is closed. Error recovery is unchanged — the character
still becomes part of the attribute name, exactly as the spec and the
existing non-leading case do.
close vuejs#13319
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe tokenizer now reports unexpected quotes and ChangesAttribute name error handling
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
close #13319
The problem
When a new tag is opened while the previous one is still unclosed, the opening
<is silently swallowed as the first character of an attribute name, and the only diagnostic is a misleadingInvalid end tag.pointing at the closing tag:<spanbecomes an attribute ofdiv, so to the parser</span>is indeed unmatched — but the reported location is the symptom, not the mistake, and the closing tag it points at visibly does have a matching open tag right before it.Root cause
The tokenizer implements the attribute name state parse error for
",'and<— but only for characters consumed while already inState.InAttrName. Per the spec,unexpected-character-in-attribute-namealso fires when one of these characters is reconsumed as the first character of the name from the before attribute name state. That reconsume path goes throughhandleAttrStart, which enteredState.InAttrNamewithout the check:The fix
handleAttrStartnow reportsUNEXPECTED_CHARACTER_IN_ATTRIBUTE_NAMEfor a leading",'or<, under the same__DEV__ || !__BROWSER__guard as the existing in-name check. Error recovery is untouched: the character still becomes part of the attribute name and the resulting AST is unchanged, exactly as in the non-leading case. The snippet above now reportswith the first error sitting exactly on the
<of<span>.Regarding the concern about compile-time failures on browser-tolerated input: this doesn't introduce a new failure mode. This input already failed to compile (
Invalid end tag.), the HTML spec itself classifies the leading character as a (recoverable) parse error, and the compiler already reports the identical error for the identical characters one position later. The change only removes the first-character blind spot so the error carries a useful location.Tests
Four new cases in the parse error table: the three leading characters mirroring the existing
a"bc=''/a'bc=''/a<bc=''cases, plus the scenario from the issue asserting both errors with exact locations.Summary by CodeRabbit