Skip to content

Conversation

@raxbg
Copy link
Contributor

@raxbg raxbg commented Feb 5, 2019

Browsers seem to stop CSS parsing on unmatched braces count for the at-rules. I guess we should do the same.

}

function testUnmachedBracesInFile() {
$oDoc = $this->parsedStructureForFile('unmached_braces', Settings::create()->withMultibyteSupport(true));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo in file name unmatched_braces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lolz, not only in the file name 😅

$sArgs = trim($oParserState->consumeUntil('{', false, true));
if (substr_count($sArgs, "(") != substr_count($sArgs, ")")) {
if($oParserState->getSettings()->bLenientParsing) {
return NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this mean there’s a null item in the resulting document’s contents? Or does the calling code ignore returned nulls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no null elements in the resulting document. The calling code looks like this:

			$oListItem = null;
			if($bLenientParsing) {
				try {
					$oListItem = self::parseListItem($oParserState, $oList);
				} catch (UnexpectedTokenException $e) {
					$oListItem = false;
				}
			} else {
				$oListItem = self::parseListItem($oParserState, $oList);
			}
			if($oListItem === null) {
				// List parsing finished
				return;
			}

Returning null aborts further parsing, which is the desired behavior. Otherwise the resulting CSS will (most likely) be valid which will change the final rendering of pages with this issue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I get it now, thanks…

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presume you meant “resulting CSS will (most likely) be _in_valid”

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant "valid", in the sense that the broken rules will be discarded, but the rest of the rules, which I presume are valid, will be included in the file.

However, this will be an issue, since those rules have been previously ignored by the browsers, so including them will most likely alter the final rendering of the page.

//Unknown other at rule (font-face or such)
$sArgs = trim($oParserState->consumeUntil('{', false, true));
if (substr_count($sArgs, "(") != substr_count($sArgs, ")")) {
if($oParserState->getSettings()->bLenientParsing) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this if? Can’t we just throw an UnsupportedTokenException instead of a SourceException and the calling code will catch it in lenient mode? If that’s not the case, maybe it should be…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwing an UnsupportedTokenException will not abort parsing, which leads to other kind of issues.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard this, then…

@MyIntervals MyIntervals deleted a comment Feb 7, 2019
@MyIntervals MyIntervals deleted a comment Feb 7, 2019
@sabberworm sabberworm merged commit acc248c into MyIntervals:master Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants