-
Notifications
You must be signed in to change notification settings - Fork 143
Keyframe selector validation #168
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
sabberworm
merged 3 commits into
MyIntervals:master
from
raxbg:keyframe_selector_validation
Nov 12, 2019
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Sabberworm\CSS\Property; | ||
|
||
use Sabberworm\CSS\Parsing\UnexpectedTokenException; | ||
|
||
class KeyframeSelector extends Selector { | ||
|
||
//Regexes for specificity calculations | ||
|
||
const SELECTOR_VALIDATION_RX = '/ | ||
^( | ||
(?: | ||
[a-zA-Z0-9\x{00A0}-\x{FFFF}_^$|*="\'~\[\]()\-\s\.:#+>]* # any sequence of valid unescaped characters | ||
(?:\\\\.)? # a single escaped character | ||
(?:([\'"]).*?(?<!\\\\)\2)? # a quoted text like [id="example"] | ||
)* | ||
)| | ||
(\d+%) # keyframe animation progress percentage (e.g. 50%) | ||
$ | ||
/ux'; | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,14 @@ | |
use Sabberworm\CSS\Parsing\OutputException; | ||
use Sabberworm\CSS\Parsing\UnexpectedTokenException; | ||
use Sabberworm\CSS\Property\Selector; | ||
use Sabberworm\CSS\Property\KeyframeSelector; | ||
use Sabberworm\CSS\Rule\Rule; | ||
use Sabberworm\CSS\Value\RuleValueList; | ||
use Sabberworm\CSS\Value\Value; | ||
use Sabberworm\CSS\Value\Size; | ||
use Sabberworm\CSS\Value\Color; | ||
use Sabberworm\CSS\Value\URL; | ||
use Sabberworm\CSS\CSSList\KeyFrame; | ||
|
||
/** | ||
* Declaration blocks are the parts of a css file which denote the rules belonging to a selector. | ||
|
@@ -26,7 +28,7 @@ public function __construct($iLineNo = 0) { | |
$this->aSelectors = array(); | ||
} | ||
|
||
public static function parse(ParserState $oParserState) { | ||
public static function parse(ParserState $oParserState, $oList = NULL) { | ||
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. |
||
$aComments = array(); | ||
$oResult = new DeclarationBlock($oParserState->currentLine()); | ||
try { | ||
|
@@ -42,7 +44,7 @@ public static function parse(ParserState $oParserState) { | |
} | ||
} | ||
} while (!in_array($oParserState->peek(), array('{', '}')) || $sStringWrapperChar !== false); | ||
$oResult->setSelector(implode('', $aSelectorParts)); | ||
$oResult->setSelector(implode('', $aSelectorParts), $oList); | ||
if ($oParserState->comes('{')) { | ||
$oParserState->consume(1); | ||
} | ||
|
@@ -62,18 +64,25 @@ public static function parse(ParserState $oParserState) { | |
} | ||
|
||
|
||
public function setSelectors($mSelector) { | ||
public function setSelectors($mSelector, $oList = NULL) { | ||
if (is_array($mSelector)) { | ||
$this->aSelectors = $mSelector; | ||
} else { | ||
$this->aSelectors = explode(',', $mSelector); | ||
} | ||
foreach ($this->aSelectors as $iKey => $mSelector) { | ||
if (!($mSelector instanceof Selector)) { | ||
if (!Selector::isValid($mSelector)) { | ||
throw new UnexpectedTokenException("Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.", $mSelector, "custom"); | ||
if ($oList === NULL || !($oList instanceof KeyFrame)) { | ||
if (!Selector::isValid($mSelector)) { | ||
throw new UnexpectedTokenException("Selector did not match '" . Selector::SELECTOR_VALIDATION_RX . "'.", $mSelector, "custom"); | ||
} | ||
$this->aSelectors[$iKey] = new Selector($mSelector); | ||
} else { | ||
if (!KeyframeSelector::isValid($mSelector)) { | ||
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. |
||
throw new UnexpectedTokenException("Selector did not match '" . KeyframeSelector::SELECTOR_VALIDATION_RX . "'.", $mSelector, "custom"); | ||
} | ||
$this->aSelectors[$iKey] = new KeyframeSelector($mSelector); | ||
} | ||
$this->aSelectors[$iKey] = new Selector($mSelector); | ||
} | ||
} | ||
} | ||
|
@@ -102,8 +111,8 @@ public function getSelector() { | |
/** | ||
* @deprecated use setSelectors() | ||
*/ | ||
public function setSelector($mSelector) { | ||
$this->setSelectors($mSelector); | ||
public function setSelector($mSelector, $oList = NULL) { | ||
$this->setSelectors($mSelector, $oList); | ||
} | ||
|
||
/** | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@-webkit-keyframes zoom { | ||
0% { | ||
-webkit-transform: scale(1,1); | ||
} | ||
50% { | ||
-webkit-transform: scale(1.2,1.2); | ||
} | ||
100% { | ||
-webkit-transform: scale(1,1); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.