-
Notifications
You must be signed in to change notification settings - Fork 36
Throw syntax errors for invalid EndTags #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
7f24f68
0d213ee
4a756e9
ca74152
7b27974
c212800
aecb392
2b44185
2d27f35
f3c022c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,18 +266,18 @@ export default class EventedTokenizer { | |
endTagName() { | ||
let char = this.consume(); | ||
|
||
if (isSpace(char)) { | ||
this.transitionTo(TokenizerState.beforeAttributeName); | ||
this.tagNameBuffer = ''; | ||
if (isSpace(char) && isAlpha(this.peek())) { | ||
this.delegate.reportSyntaxError('closing tag must only contain tagname'); | ||
} else if (char === '/') { | ||
this.transitionTo(TokenizerState.selfClosingStartTag); | ||
this.tagNameBuffer = ''; | ||
this.delegate.reportSyntaxError('closing tag cannot be self-closing'); | ||
} else if (char === '>') { | ||
this.delegate.finishTag(); | ||
this.transitionTo(TokenizerState.beforeData); | ||
this.tagNameBuffer = ''; | ||
} else { | ||
this.appendToTagName(char); | ||
if (!this.delegate.current().syntaxError && !isSpace(char)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t fully understand this conditional (reviewing on mobile so forgive me if I’ve missed something obvious). Why do we check if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right that this is confusing, and I feel like there may be a better way to do this. This check is required since we no longer enter the The |
||
this.appendToTagName(char); | ||
} | ||
} | ||
}, | ||
|
||
|
@@ -487,6 +487,10 @@ export default class EventedTokenizer { | |
this.tagNameBuffer = ''; | ||
this.delegate.beginEndTag(); | ||
this.appendToTagName(char); | ||
} else { | ||
this.transitionTo(TokenizerState.endTagName); | ||
this.delegate.beginEndTag(); | ||
this.delegate.reportSyntaxError('closing tag cannot contain whitespace before tagname'); | ||
} | ||
} | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we check if the next char is alpha here? I think the goal is to issue an error if there is white space as the first thing after the
</
, right?If so, maybe something like:
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the check for whitespace after
</
on lines 490-493 of this file:The check on line 269 is specifically looking for attributes after the EndTag's tagname. I made the decision to allow whitespace after the tagname because the HTML spec allows for this
So I'm specifically looking for whitespace followed by and ASCII alpha character (the start of an attribute), which is invalid syntax.
I've you'd prefer to completely disallow any whitespace in closing tags, I'd be happy to update this PR to check for that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya, let's do that.