Add handling of tag token emit errors in HTML Tokenizer
This commit is contained in:
+2
-1
@@ -66,7 +66,8 @@ typedef NS_ENUM(NSUInteger, HTMLTokenType)
|
||||
@interface HTMLTagToken : HTMLToken
|
||||
|
||||
@property (nonatomic, copy) NSString *tagName;
|
||||
@property (nonatomic, assign) BOOL selfClosing;
|
||||
@property (nonatomic, strong) id attributes;
|
||||
@property (nonatomic, assign, getter = isSelfClosing) BOOL selfClosing;
|
||||
|
||||
- (instancetype)initWithTagName:(NSString *)tagName;
|
||||
|
||||
|
||||
+22
-5
@@ -34,6 +34,7 @@
|
||||
HTMLDOCTYPEToken *_currentDoctypeToken;
|
||||
NSMutableString *_currentAttributeName;
|
||||
NSMutableString *_currentAttributeValue;
|
||||
BOOL _selfClosingFlagAknowledged;
|
||||
|
||||
/* Aux */
|
||||
NSString *_lastStartTagName;
|
||||
@@ -67,7 +68,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark - State Machine
|
||||
|
||||
- (void)read
|
||||
{
|
||||
@@ -105,10 +106,6 @@
|
||||
- (void)emitToken:(HTMLToken *)token
|
||||
{
|
||||
[_tokens addObject:token];
|
||||
|
||||
if (token.isStartTagToken) {
|
||||
_lastStartTagName = [(HTMLStartTagToken *)token tagName];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)emitEOFToken
|
||||
@@ -119,6 +116,26 @@
|
||||
- (void)emitCurrentTagToken
|
||||
{
|
||||
[self finalizeCurrentAttribute];
|
||||
|
||||
switch (_currentTagToken.type) {
|
||||
case HTMLTokenTypeStartTag:
|
||||
_lastStartTagName = _currentTagToken.tagName;
|
||||
if (_currentTagToken.isSelfClosing) {
|
||||
_selfClosingFlagAknowledged = NO;
|
||||
}
|
||||
break;
|
||||
case HTMLTokenTypeEndTag:
|
||||
if (_currentTagToken.attributes != nil) {
|
||||
[self emitParseError:@"End Tag Token [%@] has attributes", _currentTagToken.tagName];
|
||||
}
|
||||
if (_currentTagToken.isSelfClosing) {
|
||||
[self emitParseError:@"End Tag Token [%@] has self-closing flag", _currentTagToken.tagName];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
[self emitToken:_currentTagToken];
|
||||
_currentTagToken = nil;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user