Skip to content

Commit

Permalink
Update tokenizer and parser logic to pass latest test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab committed Apr 29, 2021
1 parent e79f96e commit 3d9f200
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 114 deletions.
34 changes: 15 additions & 19 deletions Sources/HTMLParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,7 @@ - (void)processStartTagTokenInBody:(HTMLStartTagToken *)token
_framesetOkFlag = NO;
} else if ([tagName isEqualToString:@"a"]) {
HTMLElement *element = ^ HTMLElement * {
for (HTMLElement *element in self->_listOfActiveFormattingElements.reverseObjectEnumerator) {
for (HTMLElement *element in self->_listOfActiveFormattingElements.reverseObjectEnumerator) {
if ([element isEqual:[HTMLMarker marker]]) return nil;
if ([element.tagName isEqualToString:@"a"]) {
return element;
Expand Down Expand Up @@ -2513,13 +2513,13 @@ - (void)processTokenByApplyingRulesForParsingTokensInForeignContent:(HTMLToken *
[characters enumerateSubstringsInRange:NSMakeRange(0, characters.length)
options:NSStringEnumerationByComposedCharacterSequences
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
if ([substring isEqualToString:@"\uFFFD"]) {
[self emitParseError:@"Unexpected Character (0x0000) in foreign content"];
} else if (!substring.htmlkit_isHTMLWhitespaceString) {
self->_framesetOkFlag = NO;
}
[self insertCharacters:substring];
}];
if ([substring isEqualToString:@"\uFFFD"]) {
[self emitParseError:@"Unexpected Character (0x0000) in foreign content"];
} else if (!substring.htmlkit_isHTMLWhitespaceString) {
self->_framesetOkFlag = NO;
}
[self insertCharacters:substring];
}];

return;
}
Expand All @@ -2541,23 +2541,19 @@ - (void)processTokenByApplyingRulesForParsingTokensInForeignContent:(HTMLToken *
}
[self insertForeignElementForToken:token.asTagToken inNamespace:self.adjustedCurrentNode.htmlNamespace];
if (token.asTagToken.selfClosing) {
[self->_stackOfOpenElements popCurrentNode];
[self->_stackOfOpenElements popCurrentNode];
}
};

void (^ matchedCase)(void) = ^ {
[self emitParseError:@"Unexpected start tag <%@> in foreign content", token.asTagToken.tagName];
if (self->_fragmentParsingAlgorithm) {
anythingElse();
} else {
[self->_stackOfOpenElements popCurrentNode];
while (!IsNodeMathMLTextIntegrationPoint(self.currentNode) &&
!IsNodeHTMLIntegrationPoint(self.currentNode) &&
self.currentNode.htmlNamespace != HTMLNamespaceHTML) {
[self->_stackOfOpenElements popCurrentNode];
}
[self reprocessToken:token];

while (!IsNodeMathMLTextIntegrationPoint(self.currentNode) &&
!IsNodeHTMLIntegrationPoint(self.currentNode) &&
self.currentNode.htmlNamespace != HTMLNamespaceHTML) {
[self->_stackOfOpenElements popCurrentNode];
}
[self processToken:token byApplyingRulesForInsertionMode:HTMLInsertionModeInBody];
};

if ([token.asTagToken.tagName isEqualToAny:@"b", @"big", @"blockquote", @"body", @"br",
Expand Down
1 change: 1 addition & 0 deletions Sources/HTMLTokenizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,7 @@ - (void)HTMLTokenizerStateNamedCharacterReference
usingComparator:^ NSComparisonResult (id obj1, id obj2) { return [obj1 compare:obj2]; }];

if (searchIndex >= entities.count || ![[entities objectAtIndex:searchIndex] hasPrefix:name]) {
[name setString:[name substringToIndex:name.length -1]];
break;
}

Expand Down
193 changes: 98 additions & 95 deletions Sources/include/HTMLElementAdjustment.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,64 +29,66 @@ NS_INLINE void AdjustSVGAttributes(HTMLTagToken *token)
return;
}

NSDictionary *replacements = @{@"attributename": @"attributeName",
@"attributetype": @"attributeType",
@"basefrequency": @"baseFrequency",
@"baseprofile": @"baseProfile",
@"calcmode": @"calcMode",
@"clippathunits": @"clipPathUnits",
@"diffuseconstant": @"diffuseConstant",
@"edgemode": @"edgeMode",
@"filterunits": @"filterUnits",
@"glyphref": @"glyphRef",
@"gradienttransform": @"gradientTransform",
@"gradientunits": @"gradientUnits",
@"kernelmatrix": @"kernelMatrix",
@"kernelunitlength": @"kernelUnitLength",
@"keypoints": @"keyPoints",
@"keysplines": @"keySplines",
@"keytimes": @"keyTimes",
@"lengthadjust": @"lengthAdjust",
@"limitingconeangle": @"limitingConeAngle",
@"markerheight": @"markerHeight",
@"markerunits": @"markerUnits",
@"markerwidth": @"markerWidth",
@"maskcontentunits": @"maskContentUnits",
@"maskunits": @"maskUnits",
@"numoctaves": @"numOctaves",
@"pathlength": @"pathLength",
@"patterncontentunits": @"patternContentUnits",
@"patterntransform": @"patternTransform",
@"patternunits": @"patternUnits",
@"pointsatx": @"pointsAtX",
@"pointsaty": @"pointsAtY",
@"pointsatz": @"pointsAtZ",
@"preservealpha": @"preserveAlpha",
@"preserveaspectratio": @"preserveAspectRatio",
@"primitiveunits": @"primitiveUnits",
@"refx": @"refX",
@"refy": @"refY",
@"repeatcount": @"repeatCount",
@"repeatdur": @"repeatDur",
@"requiredextensions": @"requiredExtensions",
@"requiredfeatures": @"requiredFeatures",
@"specularconstant": @"specularConstant",
@"specularexponent": @"specularExponent",
@"spreadmethod": @"spreadMethod",
@"startoffset": @"startOffset",
@"stddeviation": @"stdDeviation",
@"stitchtiles": @"stitchTiles",
@"surfacescale": @"surfaceScale",
@"systemlanguage": @"systemLanguage",
@"tablevalues": @"tableValues",
@"targetx": @"targetX",
@"targety": @"targetY",
@"textlength": @"textLength",
@"viewbox": @"viewBox",
@"viewtarget": @"viewTarget",
@"xchannelselector": @"xChannelSelector",
@"ychannelselector": @"yChannelSelector",
@"zoomandpan": @"zoomAndPan"};
NSDictionary *replacements = @{
@"attributename": @"attributeName",
@"attributetype": @"attributeType",
@"basefrequency": @"baseFrequency",
@"baseprofile": @"baseProfile",
@"calcmode": @"calcMode",
@"clippathunits": @"clipPathUnits",
@"diffuseconstant": @"diffuseConstant",
@"edgemode": @"edgeMode",
@"filterunits": @"filterUnits",
@"glyphref": @"glyphRef",
@"gradienttransform": @"gradientTransform",
@"gradientunits": @"gradientUnits",
@"kernelmatrix": @"kernelMatrix",
@"kernelunitlength": @"kernelUnitLength",
@"keypoints": @"keyPoints",
@"keysplines": @"keySplines",
@"keytimes": @"keyTimes",
@"lengthadjust": @"lengthAdjust",
@"limitingconeangle": @"limitingConeAngle",
@"markerheight": @"markerHeight",
@"markerunits": @"markerUnits",
@"markerwidth": @"markerWidth",
@"maskcontentunits": @"maskContentUnits",
@"maskunits": @"maskUnits",
@"numoctaves": @"numOctaves",
@"pathlength": @"pathLength",
@"patterncontentunits": @"patternContentUnits",
@"patterntransform": @"patternTransform",
@"patternunits": @"patternUnits",
@"pointsatx": @"pointsAtX",
@"pointsaty": @"pointsAtY",
@"pointsatz": @"pointsAtZ",
@"preservealpha": @"preserveAlpha",
@"preserveaspectratio": @"preserveAspectRatio",
@"primitiveunits": @"primitiveUnits",
@"refx": @"refX",
@"refy": @"refY",
@"repeatcount": @"repeatCount",
@"repeatdur": @"repeatDur",
@"requiredextensions": @"requiredExtensions",
@"requiredfeatures": @"requiredFeatures",
@"specularconstant": @"specularConstant",
@"specularexponent": @"specularExponent",
@"spreadmethod": @"spreadMethod",
@"startoffset": @"startOffset",
@"stddeviation": @"stdDeviation",
@"stitchtiles": @"stitchTiles",
@"surfacescale": @"surfaceScale",
@"systemlanguage": @"systemLanguage",
@"tablevalues": @"tableValues",
@"targetx": @"targetX",
@"targety": @"targetY",
@"textlength": @"textLength",
@"viewbox": @"viewBox",
@"viewtarget": @"viewTarget",
@"xchannelselector": @"xChannelSelector",
@"ychannelselector": @"yChannelSelector",
@"zoomandpan": @"zoomAndPan"
};

HTMLOrderedDictionary *adjusted = [HTMLOrderedDictionary new];
for (id key in token.attributes) {
Expand All @@ -99,43 +101,44 @@ NS_INLINE void AdjustSVGAttributes(HTMLTagToken *token)
NS_INLINE void AdjustSVGNameCase(HTMLTagToken *token)
{
NSDictionary *replacements = @{
@"altglyph": @"altGlyph",
@"altglyphdef": @"altGlyphDef",
@"altglyphitem": @"altGlyphItem",
@"animatecolor": @"animateColor",
@"animatemotion": @"animateMotion",
@"animatetransform": @"animateTransform",
@"clippath": @"clipPath",
@"feblend": @"feBlend",
@"fecolormatrix": @"feColorMatrix",
@"fecomponenttransfer": @"feComponentTransfer",
@"fecomposite": @"feComposite",
@"feconvolvematrix": @"feConvolveMatrix",
@"fediffuselighting": @"feDiffuseLighting",
@"fedisplacementmap": @"feDisplacementMap",
@"fedistantlight": @"feDistantLight",
@"fedropshadow": @"feDropShadow",
@"feflood": @"feFlood",
@"fefunca": @"feFuncA",
@"fefuncb": @"feFuncB",
@"fefuncg": @"feFuncG",
@"fefuncr": @"feFuncR",
@"fegaussianblur": @"feGaussianBlur",
@"feimage": @"feImage",
@"femerge": @"feMerge",
@"femergenode": @"feMergeNode",
@"femorphology": @"feMorphology",
@"feoffset": @"feOffset",
@"fepointlight": @"fePointLight",
@"fespecularlighting": @"feSpecularLighting",
@"fespotlight": @"feSpotLight",
@"fetile": @"feTile",
@"feturbulence": @"feTurbulence",
@"foreignobject": @"foreignObject",
@"glyphref": @"glyphRef",
@"lineargradient": @"linearGradient",
@"radialgradient": @"radialGradient",
@"textpath": @"textPath"};
@"altglyph": @"altGlyph",
@"altglyphdef": @"altGlyphDef",
@"altglyphitem": @"altGlyphItem",
@"animatecolor": @"animateColor",
@"animatemotion": @"animateMotion",
@"animatetransform": @"animateTransform",
@"clippath": @"clipPath",
@"feblend": @"feBlend",
@"fecolormatrix": @"feColorMatrix",
@"fecomponenttransfer": @"feComponentTransfer",
@"fecomposite": @"feComposite",
@"feconvolvematrix": @"feConvolveMatrix",
@"fediffuselighting": @"feDiffuseLighting",
@"fedisplacementmap": @"feDisplacementMap",
@"fedistantlight": @"feDistantLight",
@"fedropshadow": @"feDropShadow",
@"feflood": @"feFlood",
@"fefunca": @"feFuncA",
@"fefuncb": @"feFuncB",
@"fefuncg": @"feFuncG",
@"fefuncr": @"feFuncR",
@"fegaussianblur": @"feGaussianBlur",
@"feimage": @"feImage",
@"femerge": @"feMerge",
@"femergenode": @"feMergeNode",
@"femorphology": @"feMorphology",
@"feoffset": @"feOffset",
@"fepointlight": @"fePointLight",
@"fespecularlighting": @"feSpecularLighting",
@"fespotlight": @"feSpotLight",
@"fetile": @"feTile",
@"feturbulence": @"feTurbulence",
@"foreignobject": @"foreignObject",
@"glyphref": @"glyphRef",
@"lineargradient": @"linearGradient",
@"radialgradient": @"radialGradient",
@"textpath": @"textPath"
};

NSString *replacement = replacements[token.tagName] ?: token.tagName;
token.tagName = replacement;
Expand Down

0 comments on commit 3d9f200

Please sign in to comment.