Skip to content

Fix undefined index notice when property lacks value #154

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

Merged
merged 2 commits into from
Jan 29, 2019

Conversation

westonruter
Copy link
Collaborator

Given this CSS:

div {
	display: inline-block;
	display:
}

I'm getting a PHP notice:

PHP Notice:  Undefined offset: 0 in .../sabberworm/php-css-parser/lib/Sabberworm/CSS/Value/Value.php on line 58

This PR fixes that problem by improving the resiliency to bad CSS.

Copy link
Collaborator

@sabberworm sabberworm left a comment

Choose a reason for hiding this comment

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

Thanks. I think we should leverage the existing distinction between strict and lenient parsing modes.

Also, could you maybe add a unit test for this?

@@ -55,6 +55,9 @@ public static function parseValue(ParserState $oParserState, $aListDelimiters =
array_splice($aStack, $iStartPosition - 1, $iLength * 2 - 1, array($oList));
}
}
if (!isset($aStack[0])) {
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.

Could you try to instead to throw a custom UnexpectedTokenException which, in lenient mode, should be caught already.

@westonruter
Copy link
Collaborator Author

@sabberworm thanks for the review. I've added the throwing of UnexpectedTokenException in 2c61b73 along with tests.

Copy link
Collaborator

@sabberworm sabberworm left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@sabberworm sabberworm merged commit 5cf8479 into MyIntervals:master Jan 29, 2019
@westonruter westonruter deleted the fix/undefined-index branch January 29, 2019 18:26
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