diff --git a/composer.json b/composer.json index 22a876ac47c2..9c35d847b843 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "ext-json": "*", "ext-libxml": "*", "ext-mbstring": "*", - "ampproject/amp-wp": "^2.0.4", + "ampproject/amp-wp": "^2.0.5", "civicrm/composer-downloads-plugin": "^3.0", "cweagans/composer-patches": "^1.6", "mcaskill/composer-exclude-files": "^2.0", @@ -23,7 +23,6 @@ }, "require-dev": { "automattic/vipwpcs": "^2.1", - "civicrm/composer-downloads-plugin": "^3.0", "dealerdirect/phpcodesniffer-composer-installer": "^0.7", "php-stubs/wordpress-stubs": "^5.5", "phpcompatibility/phpcompatibility-wp": "^2.1", @@ -53,14 +52,28 @@ "type": "phar" } }, - "enable-patching": false, "exclude-from-files": [ "ampproject/amp-wp/back-compat/back-compat.php", "ampproject/amp-wp/includes/amp-helper-functions.php", "ampproject/amp-wp/includes/admin/functions.php", "ampproject/amp-wp/includes/deprecated.php", "ampproject/amp-wp/docs/includes/register-wp-cli-commands.php" - ] + ], + "patches": { + "sabberworm/php-css-parser": { + "Add additional validation for size unit ": "https://github.com/sabberworm/PHP-CSS-Parser/compare/3bc5ded67d77a52b81608cfc97f23b1bb0678e2f%5E...468da3441945e9c1bf402a3340b1d8326723f7d9.patch", + "Fix parsing CSS selectors which contain commas ": "https://github.com/westonruter/PHP-CSS-Parser/compare/master...10a2501c119abafced3e4014aa3c0a3453a86f67.patch" + } + }, + "patches-ignore": { + "ampproject/amp-wp": { + "sabberworm/php-css-parser": { + "Add additional validation for size unit ": "patches/php-css-parser-pull-193.patch", + "Validate name-start code points for identifier ": "patches/php-css-parser-pull-185.patch", + "Fix parsing CSS selectors which contain commas ": "patches/php-css-parser-commit-10a2501.patch" + } + } + } }, "autoload": { "psr-4": { @@ -83,6 +96,11 @@ "type": "vcs", "url": "https://github.com/ampproject/amp-wp", "no-api": true + }, + { + "type": "vcs", + "url": "https://github.com/sabberworm/PHP-CSS-Parser.git", + "no-api": true } ], "minimum-stability": "dev", diff --git a/composer.lock b/composer.lock index 10a011a72308..28b1c54da32d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "623bea96c330d3d8fb2787236c921ee7", + "content-hash": "0f19f6006aeee3114d54a0769bef5fb0", "packages": [ { "name": "ampproject/amp-wp", @@ -326,12 +326,17 @@ "phpunit/phpunit": "^4.8.36" }, "type": "library", + "extra": { + "patches_applied": { + "Add additional validation for size unit ": "https://github.com/sabberworm/PHP-CSS-Parser/compare/3bc5ded67d77a52b81608cfc97f23b1bb0678e2f%5E...468da3441945e9c1bf402a3340b1d8326723f7d9.patch", + "Fix parsing CSS selectors which contain commas ": "https://github.com/westonruter/PHP-CSS-Parser/compare/master...10a2501c119abafced3e4014aa3c0a3453a86f67.patch" + } + }, "autoload": { "psr-4": { "Sabberworm\\CSS\\": "lib/Sabberworm/CSS/" } }, - "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], diff --git a/patches/php-css-parser-commit-10a2501.patch b/patches/php-css-parser-commit-10a2501.patch deleted file mode 100644 index ca0f792c4b99..000000000000 --- a/patches/php-css-parser-commit-10a2501.patch +++ /dev/null @@ -1,143 +0,0 @@ -From fa139f65c5b098ae652c970b25e6eb03fc495eb4 Mon Sep 17 00:00:00 2001 -From: Weston Ruter -Date: Wed, 25 Jul 2018 10:38:59 -0700 -Subject: [PATCH 1/2] Fix parsing CSS selectors which contain commas - ---- - .../CSS/RuleSet/DeclarationBlock.php | 60 ++++++++++++++++++- - tests/Sabberworm/CSS/ParserTest.php | 6 ++ - tests/files/specificity.css | 4 +- - 3 files changed, 68 insertions(+), 2 deletions(-) - -diff --git a/lib/Sabberworm/CSS/RuleSet/DeclarationBlock.php b/lib/Sabberworm/CSS/RuleSet/DeclarationBlock.php -index e18f5d8..26c2e12 100644 ---- a/lib/Sabberworm/CSS/RuleSet/DeclarationBlock.php -+++ b/lib/Sabberworm/CSS/RuleSet/DeclarationBlock.php -@@ -28,7 +28,19 @@ public function setSelectors($mSelector) { - if (is_array($mSelector)) { - $this->aSelectors = $mSelector; - } else { -- $this->aSelectors = explode(',', $mSelector); -+ list( $sSelectors, $aPlaceholders ) = $this->addSelectorExpressionPlaceholders( $mSelector ); -+ if ( empty( $aPlaceholders ) ) { -+ $this->aSelectors = explode(',', $sSelectors); -+ } else { -+ $aSearches = array_keys( $aPlaceholders ); -+ $aReplaces = array_values( $aPlaceholders ); -+ $this->aSelectors = array_map( -+ function( $sSelector ) use ( $aSearches, $aReplaces ) { -+ return str_replace( $aSearches, $aReplaces, $sSelector ); -+ }, -+ explode(',', $sSelectors) -+ ); -+ } - } - foreach ($this->aSelectors as $iKey => $mSelector) { - if (!($mSelector instanceof Selector)) { -@@ -37,6 +49,52 @@ public function setSelectors($mSelector) { - } - } - -+ /** -+ * Add placeholders for parenthetical/bracketed expressions in selectors which may contain commas that break exploding. -+ * -+ * This prevents a single selector like `.widget:not(.foo, .bar)` from erroneously getting parsed in setSelectors as -+ * two selectors `.widget:not(.foo` and `.bar)`. -+ * -+ * @param string $sSelectors Selectors. -+ * @return array First array value is the selectors with placeholders, and second value is the array of placeholders mapped to the original expressions. -+ */ -+ private function addSelectorExpressionPlaceholders( $sSelectors ) { -+ $iOffset = 0; -+ $aPlaceholders = array(); -+ -+ while ( preg_match( '/\(|\[/', $sSelectors, $aMatches, PREG_OFFSET_CAPTURE, $iOffset ) ) { -+ $sMatchString = $aMatches[0][0]; -+ $iMatchOffset = $aMatches[0][1]; -+ $iStyleLength = strlen( $sSelectors ); -+ $iOpenParens = 1; -+ $iStartOffset = $iMatchOffset + strlen( $sMatchString ); -+ $iFinalOffset = $iStartOffset; -+ for ( ; $iFinalOffset < $iStyleLength; $iFinalOffset++ ) { -+ if ( '(' === $sSelectors[ $iFinalOffset ] || '[' === $sSelectors[ $iFinalOffset ] ) { -+ $iOpenParens++; -+ } elseif ( ')' === $sSelectors[ $iFinalOffset ] || ']' === $sSelectors[ $iFinalOffset ] ) { -+ $iOpenParens--; -+ } -+ -+ // Found the end of the expression, so replace it with a placeholder. -+ if ( 0 === $iOpenParens ) { -+ $sMatchedExpr = substr( $sSelectors, $iMatchOffset, $iFinalOffset - $iMatchOffset + 1 ); -+ $sPlaceholder = sprintf( '{placeholder:%d}', count( $aPlaceholders ) + 1 ); -+ $aPlaceholders[ $sPlaceholder ] = $sMatchedExpr; -+ -+ // Update the CSS to replace the matched calc() with the placeholder function. -+ $sSelectors = substr( $sSelectors, 0, $iMatchOffset ) . $sPlaceholder . substr( $sSelectors, $iFinalOffset + 1 ); -+ // Update offset based on difference of length of placeholder vs original matched calc(). -+ $iFinalOffset += strlen( $sPlaceholder ) - strlen( $sMatchedExpr ); -+ break; -+ } -+ } -+ // Start matching at the next byte after the match. -+ $iOffset = $iFinalOffset + 1; -+ } -+ return array( $sSelectors, $aPlaceholders ); -+ } -+ - // remove one of the selector of the block - public function removeSelector($mSelector) { - if($mSelector instanceof Selector) { -diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php -index 43c22e2..a5073be 100644 ---- a/tests/Sabberworm/CSS/ParserTest.php -+++ b/tests/Sabberworm/CSS/ParserTest.php -@@ -148,6 +148,12 @@ function testSpecificity() { - case "li.green": - $this->assertSame(11, $oSelector->getSpecificity()); - break; -+ case "div:not(.foo[title=\"a,b\"], .bar)": -+ $this->assertSame(31, $oSelector->getSpecificity()); -+ break; -+ case "div[title=\"a,b\"]": -+ $this->assertSame(11, $oSelector->getSpecificity()); -+ break; - default: - $this->fail("specificity: untested selector " . $oSelector->getSelector()); - } -diff --git a/tests/files/specificity.css b/tests/files/specificity.css -index 82a2939..df03ff0 100644 ---- a/tests/files/specificity.css -+++ b/tests/files/specificity.css -@@ -2,6 +2,8 @@ - #file, - .help:hover, - li.green, --ol li::before { -+ol li::before, -+div:not(.foo[title="a,b"], .bar), -+div[title="a,b"] { - font-family: Helvetica; - } - -From 10a2501c119abafced3e4014aa3c0a3453a86f67 Mon Sep 17 00:00:00 2001 -From: Weston Ruter -Date: Mon, 20 Apr 2020 13:53:44 -0700 -Subject: [PATCH 2/2] Update SELECTOR_VALIDATION_RX to account for - parenthetical groups - ---- - lib/Sabberworm/CSS/Property/Selector.php | 1 + - 1 file changed, 1 insertion(+) - -diff --git a/lib/Sabberworm/CSS/Property/Selector.php b/lib/Sabberworm/CSS/Property/Selector.php -index bd04b88..0f1c643 100644 ---- a/lib/Sabberworm/CSS/Property/Selector.php -+++ b/lib/Sabberworm/CSS/Property/Selector.php -@@ -43,6 +43,7 @@ class Selector { - [a-zA-Z0-9\x{00A0}-\x{FFFF}_^$|*="\'~\[\]()\-\s\.:#+>]* # any sequence of valid unescaped characters - (?:\\\\.)? # a single escaped character - (?:([\'"]).*?(? -Date: Wed, 22 Jan 2020 01:00:18 -0500 -Subject: [PATCH 1/5] Validate name-start code points for identifier - ---- - lib/Sabberworm/CSS/Parsing/ParserState.php | 40 +++++++++++++++++----- - lib/Sabberworm/CSS/Value/Color.php | 2 +- - tests/Sabberworm/CSS/ParserTest.php | 13 +++++-- - tests/files/-invalid-identifier.css | 6 ++++ - 4 files changed, 48 insertions(+), 13 deletions(-) - create mode 100644 tests/files/-invalid-identifier.css - -diff --git a/lib/Sabberworm/CSS/Parsing/ParserState.php b/lib/Sabberworm/CSS/Parsing/ParserState.php -index ad79820..1914f22 100644 ---- a/lib/Sabberworm/CSS/Parsing/ParserState.php -+++ b/lib/Sabberworm/CSS/Parsing/ParserState.php -@@ -48,8 +48,30 @@ public function getSettings() { - return $this->oParserSettings; - } - -- public function parseIdentifier($bIgnoreCase = true) { -- $sResult = $this->parseCharacter(true); -+ public function parseIdentifier($bIgnoreCase = true, $bNameStartCodePoint = true) { -+ $sResult = null; -+ $bCanParseCharacter = true; -+ -+ if ( $bNameStartCodePoint ) { -+ // Check if 3 code points would start an identifier. See . -+ $sNameStartCodePoint = '[a-zA-Z_]|[\x80-\xFF}]'; -+ $sEscapeCode = '\\[^\r\n\f]'; -+ -+ if ( -+ ! ( -+ preg_match("/-([-${sNameStartCodePoint}]|${sEscapeCode})/isSu", $this->peek(3)) || -+ preg_match("/${sNameStartCodePoint}/isSu", $this->peek()) || -+ preg_match("/${sEscapeCode}/isS", $this->peek(2)) -+ ) -+ ) { -+ $bCanParseCharacter = false; -+ } -+ } -+ -+ if ( $bCanParseCharacter ) { -+ $sResult = $this->parseCharacter(true); -+ } -+ - if ($sResult === null) { - throw new UnexpectedTokenException($sResult, $this->peek(5), 'identifier', $this->iLineNo); - } -@@ -97,13 +119,13 @@ public function parseCharacter($bIsForIdentifier) { - } - if ($bIsForIdentifier) { - $peek = ord($this->peek()); -- // Ranges: a-z A-Z 0-9 - _ -+ // Matches a name code point. See . - if (($peek >= 97 && $peek <= 122) || - ($peek >= 65 && $peek <= 90) || - ($peek >= 48 && $peek <= 57) || - ($peek === 45) || - ($peek === 95) || -- ($peek > 0xa1)) { -+ ($peek > 0x81)) { - return $this->consume(1); - } - } else { -@@ -261,22 +283,22 @@ public function strlen($sString) { - return mb_strlen($sString, $this->sCharset); - } else { - return strlen($sString); -- } -- } -+ } -+ } - - private function substr($iStart, $iLength) { - if ($iLength < 0) { - $iLength = $this->iLength - $iStart + $iLength; -- } -+ } - if ($iStart + $iLength > $this->iLength) { - $iLength = $this->iLength - $iStart; -- } -+ } - $sResult = ''; - while ($iLength > 0) { - $sResult .= $this->aText[$iStart]; - $iStart++; - $iLength--; -- } -+ } - return $sResult; - } - -diff --git a/lib/Sabberworm/CSS/Value/Color.php b/lib/Sabberworm/CSS/Value/Color.php -index c6ed9b1..f02777f 100644 ---- a/lib/Sabberworm/CSS/Value/Color.php -+++ b/lib/Sabberworm/CSS/Value/Color.php -@@ -14,7 +14,7 @@ public static function parse(ParserState $oParserState) { - $aColor = array(); - if ($oParserState->comes('#')) { - $oParserState->consume('#'); -- $sValue = $oParserState->parseIdentifier(false); -+ $sValue = $oParserState->parseIdentifier(false, false); - if ($oParserState->strlen($sValue) === 3) { - $sValue = $sValue[0] . $sValue[0] . $sValue[1] . $sValue[1] . $sValue[2] . $sValue[2]; - } else if ($oParserState->strlen($sValue) === 4) { -diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php -index ea34f2e..16cae89 100644 ---- a/tests/Sabberworm/CSS/ParserTest.php -+++ b/tests/Sabberworm/CSS/ParserTest.php -@@ -214,7 +214,7 @@ function testManipulation() { - $this->assertSame('#header {margin: 10px 2em 1cm 2%;color: red !important;frequency: 30Hz;} - body {color: green;}', $oDoc->render()); - } -- -+ - function testRuleGetters() { - $oDoc = $this->parsedStructureForFile('values'); - $aBlocks = $oDoc->getAllDeclarationBlocks(); -@@ -319,7 +319,7 @@ function testNamespaces() { - |test {gaga: 2;}'; - $this->assertSame($sExpected, $oDoc->render()); - } -- -+ - function testInnerColors() { - $oDoc = $this->parsedStructureForFile('inner-color'); - $sExpected = 'test {background: -webkit-gradient(linear,0 0,0 bottom,from(#006cad),to(hsl(202,100%,49%)));}'; -@@ -359,7 +359,7 @@ function testListValueRemoval() { - $this->assertSame('@media screen {html {some: -test(val2);}} - #unrelated {other: yes;}', $oDoc->render()); - } -- -+ - /** - * @expectedException Sabberworm\CSS\Parsing\OutputException - */ -@@ -766,4 +766,11 @@ function testLonelyImport() { - $sExpected = "@import url(\"example.css\") only screen and (max-width: 600px);"; - $this->assertSame($sExpected, $oDoc->render()); - } -+ -+ /** -+ * @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException -+ */ -+ function testInvalidIdentifier() { -+ $this->parsedStructureForFile('-invalid-identifier', Settings::create()->withLenientParsing(false)); -+ } - } -diff --git a/tests/files/-invalid-identifier.css b/tests/files/-invalid-identifier.css -new file mode 100644 -index 0000000..da00caf ---- /dev/null -+++ b/tests/files/-invalid-identifier.css -@@ -0,0 +1,6 @@ -+body { -+ transition: all .3s ease-in-out; -+ -webkit-transition: all .3s ease-in-out; -+ -moz-transition: all .3s ease-in-out; -+ -0-transition: all .3s ease-in-out; -+} - -From e031394fe3fc4448ed7e625e0c2b4ab334ad4ba2 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Sun, 26 Jan 2020 00:56:31 -0500 -Subject: [PATCH 2/5] Make validation of identifier more strict - ---- - lib/Sabberworm/CSS/Parsing/ParserState.php | 8 +++---- - tests/Sabberworm/CSS/ParserTest.php | 26 +++++++++++++++++++--- - tests/files/-invalid-identifier.css | 6 ----- - 3 files changed, 27 insertions(+), 13 deletions(-) - delete mode 100644 tests/files/-invalid-identifier.css - -diff --git a/lib/Sabberworm/CSS/Parsing/ParserState.php b/lib/Sabberworm/CSS/Parsing/ParserState.php -index 1914f22..2271d03 100644 ---- a/lib/Sabberworm/CSS/Parsing/ParserState.php -+++ b/lib/Sabberworm/CSS/Parsing/ParserState.php -@@ -54,14 +54,14 @@ public function parseIdentifier($bIgnoreCase = true, $bNameStartCodePoint = true - - if ( $bNameStartCodePoint ) { - // Check if 3 code points would start an identifier. See . -- $sNameStartCodePoint = '[a-zA-Z_]|[\x80-\xFF}]'; -+ $sNameStartCodePoint = '[a-zA-Z_]|[\x80-\xFF]'; - $sEscapeCode = '\\[^\r\n\f]'; - - if ( - ! ( -- preg_match("/-([-${sNameStartCodePoint}]|${sEscapeCode})/isSu", $this->peek(3)) || -- preg_match("/${sNameStartCodePoint}/isSu", $this->peek()) || -- preg_match("/${sEscapeCode}/isS", $this->peek(2)) -+ preg_match("/^-([-${sNameStartCodePoint}]|${sEscapeCode})/isSu", $this->peek(3)) || -+ preg_match("/^${sNameStartCodePoint}/isSu", $this->peek()) || -+ preg_match("/^${sEscapeCode}/isS", $this->peek(2)) - ) - ) { - $bCanParseCharacter = false; -diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php -index 16cae89..921209e 100644 ---- a/tests/Sabberworm/CSS/ParserTest.php -+++ b/tests/Sabberworm/CSS/ParserTest.php -@@ -767,10 +767,30 @@ function testLonelyImport() { - $this->assertSame($sExpected, $oDoc->render()); - } - -+ function getInvalidIdentifiers() { -+ return array( -+ array( -+ 'body { -0-transition: all .3s ease-in-out; }', -+ 'Identifier expected. Got “-0-tr” [line no: 1]' -+ ), -+ array( -+ 'body { 4-o-transition: all .3s ease-in-out; }', -+ 'Identifier expected. Got “4-o-t” [line no: 1]' -+ ) -+ ); -+ } -+ - /** -- * @expectedException \Sabberworm\CSS\Parsing\UnexpectedTokenException -+ * @dataProvider getInvalidIdentifiers - */ -- function testInvalidIdentifier() { -- $this->parsedStructureForFile('-invalid-identifier', Settings::create()->withLenientParsing(false)); -+ function testInvalidIdentifier($css, $errorMessage) { -+ try { -+ $settings = Settings::create()->withLenientParsing(false); -+ $parser = new Parser($css, $settings); -+ $parser->parse(); -+ $this->fail( 'UnexpectedTokenException not thrown' ); -+ } catch ( UnexpectedTokenException $e ) { -+ $this->assertEquals( $errorMessage, $e->getMessage() ); -+ } - } - } -diff --git a/tests/files/-invalid-identifier.css b/tests/files/-invalid-identifier.css -deleted file mode 100644 -index da00caf..0000000 ---- a/tests/files/-invalid-identifier.css -+++ /dev/null -@@ -1,6 +0,0 @@ --body { -- transition: all .3s ease-in-out; -- -webkit-transition: all .3s ease-in-out; -- -moz-transition: all .3s ease-in-out; -- -0-transition: all .3s ease-in-out; --} - -From 8fbd0fe82aa08ad2650def1b44f2f77154211e30 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Sun, 26 Jan 2020 01:08:21 -0500 -Subject: [PATCH 3/5] Refactor `testInvalidIdentifier` test - ---- - tests/Sabberworm/CSS/ParserTest.php | 27 ++++++++++----------------- - 1 file changed, 10 insertions(+), 17 deletions(-) - -diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php -index 921209e..68284ce 100644 ---- a/tests/Sabberworm/CSS/ParserTest.php -+++ b/tests/Sabberworm/CSS/ParserTest.php -@@ -769,28 +769,21 @@ function testLonelyImport() { - - function getInvalidIdentifiers() { - return array( -- array( -- 'body { -0-transition: all .3s ease-in-out; }', -- 'Identifier expected. Got “-0-tr” [line no: 1]' -- ), -- array( -- 'body { 4-o-transition: all .3s ease-in-out; }', -- 'Identifier expected. Got “4-o-t” [line no: 1]' -- ) -+ array('body { -0-transition: all .3s ease-in-out; }' ), -+ array('body { 4-o-transition: all .3s ease-in-out; }' ), - ); - } - - /** - * @dataProvider getInvalidIdentifiers -+ * -+ * @param string $css CSS text. - */ -- function testInvalidIdentifier($css, $errorMessage) { -- try { -- $settings = Settings::create()->withLenientParsing(false); -- $parser = new Parser($css, $settings); -- $parser->parse(); -- $this->fail( 'UnexpectedTokenException not thrown' ); -- } catch ( UnexpectedTokenException $e ) { -- $this->assertEquals( $errorMessage, $e->getMessage() ); -- } -+ function testInvalidIdentifier($css) { -+ $this->setExpectedException( 'Sabberworm\CSS\Parsing\UnexpectedTokenException' ); -+ -+ $oSettings = Settings::create()->withLenientParsing(false); -+ $oParser = new Parser($css, $oSettings); -+ $oParser->parse(); - } - } - -From 586c684a990458d70af55b47f584b619ad5c3a41 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Fri, 31 Jan 2020 15:55:54 -0500 -Subject: [PATCH 4/5] Recover from invalid identifier if in lenient mode - ---- - lib/Sabberworm/CSS/Parsing/ParserState.php | 2 +- - tests/Sabberworm/CSS/ParserTest.php | 4 ++-- - 2 files changed, 3 insertions(+), 3 deletions(-) - -diff --git a/lib/Sabberworm/CSS/Parsing/ParserState.php b/lib/Sabberworm/CSS/Parsing/ParserState.php -index 2271d03..7ab8e01 100644 ---- a/lib/Sabberworm/CSS/Parsing/ParserState.php -+++ b/lib/Sabberworm/CSS/Parsing/ParserState.php -@@ -72,7 +72,7 @@ public function parseIdentifier($bIgnoreCase = true, $bNameStartCodePoint = true - $sResult = $this->parseCharacter(true); - } - -- if ($sResult === null) { -+ if (!$this->oParserSettings->bLenientParsing && $sResult === null) { - throw new UnexpectedTokenException($sResult, $this->peek(5), 'identifier', $this->iLineNo); - } - $sCharacter = null; -diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php -index 68284ce..ff8c5c9 100644 ---- a/tests/Sabberworm/CSS/ParserTest.php -+++ b/tests/Sabberworm/CSS/ParserTest.php -@@ -769,8 +769,8 @@ function testLonelyImport() { - - function getInvalidIdentifiers() { - return array( -- array('body { -0-transition: all .3s ease-in-out; }' ), -- array('body { 4-o-transition: all .3s ease-in-out; }' ), -+ array('body { -0-transition: all .3s ease-in-out; }'), -+ array('body { 4-o-transition: all .3s ease-in-out; }'), - ); - } - - -From 113df5d55e94e21c6402021dfa959924941d4c29 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Fri, 14 Feb 2020 04:20:16 -0500 -Subject: [PATCH 5/5] Remove check of lenient parsing - -The thrown exception will be caught when in lenient mode ---- - lib/Sabberworm/CSS/Parsing/ParserState.php | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/lib/Sabberworm/CSS/Parsing/ParserState.php b/lib/Sabberworm/CSS/Parsing/ParserState.php -index 7ab8e01..2271d03 100644 ---- a/lib/Sabberworm/CSS/Parsing/ParserState.php -+++ b/lib/Sabberworm/CSS/Parsing/ParserState.php -@@ -72,7 +72,7 @@ public function parseIdentifier($bIgnoreCase = true, $bNameStartCodePoint = true - $sResult = $this->parseCharacter(true); - } - -- if (!$this->oParserSettings->bLenientParsing && $sResult === null) { -+ if ($sResult === null) { - throw new UnexpectedTokenException($sResult, $this->peek(5), 'identifier', $this->iLineNo); - } - $sCharacter = null; diff --git a/patches/php-css-parser-pull-193.patch b/patches/php-css-parser-pull-193.patch deleted file mode 100644 index f7794118f6c1..000000000000 --- a/patches/php-css-parser-pull-193.patch +++ /dev/null @@ -1,415 +0,0 @@ -From 2ab643b70569f703b560c9e1bfb4f25498f0dec4 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Wed, 6 May 2020 15:41:19 -0400 -Subject: [PATCH 1/7] Change turns to turn - ---- - lib/Sabberworm/CSS/Value/Size.php | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php -index 8490cc3..05f41ea 100644 ---- a/lib/Sabberworm/CSS/Value/Size.php -+++ b/lib/Sabberworm/CSS/Value/Size.php -@@ -8,7 +8,7 @@ class Size extends PrimitiveValue { - - const ABSOLUTE_SIZE_UNITS = 'px/cm/mm/mozmm/in/pt/pc/vh/vw/vmin/vmax/rem'; //vh/vw/vm(ax)/vmin/rem are absolute insofar as they don’t scale to the immediate parent (only the viewport) - const RELATIVE_SIZE_UNITS = '%/em/ex/ch/fr'; -- const NON_SIZE_UNITS = 'deg/grad/rad/s/ms/turns/Hz/kHz'; -+ const NON_SIZE_UNITS = 'deg/grad/rad/s/ms/turn/Hz/kHz'; - - private static $SIZE_UNITS = null; - --- -2.25.1 - - -From 1e0d5367444c4b5b62b12ea16737a26657ef4eac Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Mon, 11 May 2020 03:16:27 -0400 -Subject: [PATCH 2/7] Output correct size unit in lenient mode; fail if unit - not valid - ---- - lib/Sabberworm/CSS/Value/Size.php | 15 +++++++++++++-- - tests/Sabberworm/CSS/ParserTest.php | 18 ++++++++++++++++++ - 2 files changed, 31 insertions(+), 2 deletions(-) - -diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php -index 05f41ea..26ce9aa 100644 ---- a/lib/Sabberworm/CSS/Value/Size.php -+++ b/lib/Sabberworm/CSS/Value/Size.php -@@ -3,6 +3,7 @@ - namespace Sabberworm\CSS\Value; - - use Sabberworm\CSS\Parsing\ParserState; -+use Sabberworm\CSS\Parsing\UnexpectedTokenException; - - class Size extends PrimitiveValue { - -@@ -38,11 +39,21 @@ class Size extends PrimitiveValue { - - $sUnit = null; - $aSizeUnits = self::getSizeUnits(); -- foreach($aSizeUnits as $iLength => &$aValues) { -+ $sUnit = strtolower($oParserState->parseIdentifier()); -+ $oParserState->backtrack(strlen($sUnit)); -+ -+ foreach($aSizeUnits as $iLength => $aValues) { -+ $iConsumeLength = $iLength; - $sKey = strtolower($oParserState->peek($iLength)); - if(array_key_exists($sKey, $aValues)) { -+ if ($sUnit !== $sKey) { -+ if (!$oParserState->getSettings()->bLenientParsing) { -+ throw new UnexpectedTokenException('Unit', $sUnit, 'identifier', $oParserState->currentLine()); -+ } -+ $iConsumeLength = strlen($sUnit); -+ } - if (($sUnit = $aValues[$sKey]) !== null) { -- $oParserState->consume($iLength); -+ $oParserState->consume($iConsumeLength); - break; - } - } -diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php -index 4a69019..e457f99 100644 ---- a/tests/Sabberworm/CSS/ParserTest.php -+++ b/tests/Sabberworm/CSS/ParserTest.php -@@ -787,4 +787,22 @@ body {background-url: url("http://somesite.com/images/someimage.gif");}'; - $sExpected = "@import url(\"example.css\") only screen and (max-width: 600px);"; - $this->assertSame($sExpected, $oDoc->render()); - } -+ -+ function testTurnUnitLenient() { -+ $sText = ".foo {transform: rotate(1turn);}\n.bar {transform: rotate(1turns);}"; -+ $sExpected = ".foo {transform: rotate(1turn);}\n.bar {transform: rotate(1turn);}"; -+ -+ $oParser = new Parser($sText); -+ $this->assertSame($sExpected, $oParser->parse()->render()); -+ } -+ -+ function testTurnUnitStrict() { -+ $sText = ".foo {transform: rotate(1turn);}\n.bar {transform: rotate(1turns);}"; -+ -+ $oParser = new Parser($sText, Settings::create()->beStrict()); -+ -+ // Line 2 contains the invalid unit and so should be reported. -+ $this->setExpectedException( 'Sabberworm\CSS\Parsing\UnexpectedTokenException', 'Identifier expected. Got “turns” [line no: 2]' ); -+ $oParser->parse(); -+ } - } --- -2.25.1 - - -From 848e803b64cd1ced0059b83a37605e14732e568a Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Mon, 11 May 2020 11:50:58 -0400 -Subject: [PATCH 3/7] Fix parsing unit - ---- - lib/Sabberworm/CSS/Value/Size.php | 30 +++++++++++++++++++++++------- - 1 file changed, 23 insertions(+), 7 deletions(-) - -diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php -index 26ce9aa..ef12898 100644 ---- a/lib/Sabberworm/CSS/Value/Size.php -+++ b/lib/Sabberworm/CSS/Value/Size.php -@@ -37,20 +37,36 @@ class Size extends PrimitiveValue { - } - } - -- $sUnit = null; -- $aSizeUnits = self::getSizeUnits(); -- $sUnit = strtolower($oParserState->parseIdentifier()); -- $oParserState->backtrack(strlen($sUnit)); -+ $sParsedUnit = ''; -+ $iOffset = 0; -+ while (true) { -+ $sChar = $oParserState->peek(1, $iOffset); -+ $iPeek = ord($sChar); -+ -+ // Ranges: a-z A-Z 0-9 % -+ if (($iPeek >= 97 && $iPeek <= 122) || -+ ($iPeek >= 65 && $iPeek <= 90) || -+ ($iPeek >= 48 && $iPeek <= 57) || -+ ($iPeek === 37)) { -+ $sParsedUnit .= $sChar; -+ $iOffset++; -+ } else { -+ break; -+ } -+ } -+ -+ $sUnit = null; -+ $aSizeUnits = self::getSizeUnits(); - - foreach($aSizeUnits as $iLength => $aValues) { - $iConsumeLength = $iLength; - $sKey = strtolower($oParserState->peek($iLength)); - if(array_key_exists($sKey, $aValues)) { -- if ($sUnit !== $sKey) { -+ if (strtolower($sParsedUnit) !== $sKey) { - if (!$oParserState->getSettings()->bLenientParsing) { -- throw new UnexpectedTokenException('Unit', $sUnit, 'identifier', $oParserState->currentLine()); -+ throw new UnexpectedTokenException('Unit', $sParsedUnit, 'identifier', $oParserState->currentLine()); - } -- $iConsumeLength = strlen($sUnit); -+ $iConsumeLength = strlen($sParsedUnit); - } - if (($sUnit = $aValues[$sKey]) !== null) { - $oParserState->consume($iConsumeLength); --- -2.25.1 - - -From ca2d6e7dc88cca27f3e0192677baddd81f3c1c80 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Mon, 11 May 2020 15:21:45 -0400 -Subject: [PATCH 4/7] Revert truncation of unit - ---- - lib/Sabberworm/CSS/Value/Size.php | 50 +++++++++++++---------------- - tests/Sabberworm/CSS/ParserTest.php | 26 +++++++-------- - 2 files changed, 36 insertions(+), 40 deletions(-) - -diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php -index ef12898..e26a354 100644 ---- a/lib/Sabberworm/CSS/Value/Size.php -+++ b/lib/Sabberworm/CSS/Value/Size.php -@@ -37,39 +37,35 @@ class Size extends PrimitiveValue { - } - } - -- $sParsedUnit = ''; -- $iOffset = 0; -+ $sParsedUnit = ''; -+ $iOffset = 0; - while (true) { -- $sChar = $oParserState->peek(1, $iOffset); -- $iPeek = ord($sChar); -- -- // Ranges: a-z A-Z 0-9 % -- if (($iPeek >= 97 && $iPeek <= 122) || -- ($iPeek >= 65 && $iPeek <= 90) || -- ($iPeek >= 48 && $iPeek <= 57) || -- ($iPeek === 37)) { -- $sParsedUnit .= $sChar; -- $iOffset++; -- } else { -- break; -- } -- } -- -- $sUnit = null; -- $aSizeUnits = self::getSizeUnits(); -+ $sChar = $oParserState->peek(1, $iOffset); -+ $iPeek = ord($sChar); -+ -+ // Ranges: a-z A-Z 0-9 % -+ if (($iPeek >= 97 && $iPeek <= 122) || -+ ($iPeek >= 65 && $iPeek <= 90) || -+ ($iPeek >= 48 && $iPeek <= 57) || -+ ($iPeek === 37)) { -+ $sParsedUnit .= $sChar; -+ $iOffset++; -+ } else { -+ break; -+ } -+ } -+ -+ $sUnit = null; -+ $aSizeUnits = self::getSizeUnits(); - - foreach($aSizeUnits as $iLength => $aValues) { -- $iConsumeLength = $iLength; - $sKey = strtolower($oParserState->peek($iLength)); - if(array_key_exists($sKey, $aValues)) { -- if (strtolower($sParsedUnit) !== $sKey) { -- if (!$oParserState->getSettings()->bLenientParsing) { -- throw new UnexpectedTokenException('Unit', $sParsedUnit, 'identifier', $oParserState->currentLine()); -- } -- $iConsumeLength = strlen($sParsedUnit); -- } -+ if (strtolower($sParsedUnit) !== $sKey) { -+ throw new UnexpectedTokenException('Unit', $sParsedUnit, 'identifier', $oParserState->currentLine()); -+ } - if (($sUnit = $aValues[$sKey]) !== null) { -- $oParserState->consume($iConsumeLength); -+ $oParserState->consume($iLength); - break; - } - } -diff --git a/tests/Sabberworm/CSS/ParserTest.php b/tests/Sabberworm/CSS/ParserTest.php -index e457f99..6ef74bb 100644 ---- a/tests/Sabberworm/CSS/ParserTest.php -+++ b/tests/Sabberworm/CSS/ParserTest.php -@@ -788,21 +788,21 @@ body {background-url: url("http://somesite.com/images/someimage.gif");}'; - $this->assertSame($sExpected, $oDoc->render()); - } - -- function testTurnUnitLenient() { -- $sText = ".foo {transform: rotate(1turn);}\n.bar {transform: rotate(1turns);}"; -- $sExpected = ".foo {transform: rotate(1turn);}\n.bar {transform: rotate(1turn);}"; -+ function testTurnUnitLenient() { -+ $sText = ".foo {transform: rotate(1turn);}\n.bar {transform: rotate(1turns);}"; -+ $sExpected = ".foo {transform: rotate(1turn);}\n.bar {}"; - -- $oParser = new Parser($sText); -- $this->assertSame($sExpected, $oParser->parse()->render()); -- } -+ $oParser = new Parser($sText); -+ $this->assertSame($sExpected, $oParser->parse()->render()); -+ } - -- function testTurnUnitStrict() { -- $sText = ".foo {transform: rotate(1turn);}\n.bar {transform: rotate(1turns);}"; -+ function testTurnUnitStrict() { -+ $sText = ".foo {transform: rotate(1turn);}\n.bar {transform: rotate(1turns);}"; - -- $oParser = new Parser($sText, Settings::create()->beStrict()); -+ $oParser = new Parser($sText, Settings::create()->beStrict()); - -- // Line 2 contains the invalid unit and so should be reported. -- $this->setExpectedException( 'Sabberworm\CSS\Parsing\UnexpectedTokenException', 'Identifier expected. Got “turns” [line no: 2]' ); -- $oParser->parse(); -- } -+ // Line 2 contains the invalid unit and so should be reported. -+ $this->setExpectedException( 'Sabberworm\CSS\Parsing\UnexpectedTokenException', 'Identifier expected. Got “turns” [line no: 2]' ); -+ $oParser->parse(); -+ } - } --- -2.25.1 - - -From d35c18f6924b2d26fac666a400ca5018beb61324 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Mon, 11 May 2020 17:10:41 -0400 -Subject: [PATCH 5/7] Simplify logic for parsing size unit - ---- - lib/Sabberworm/CSS/Value/Size.php | 24 ++++++------------------ - 1 file changed, 6 insertions(+), 18 deletions(-) - -diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php -index e26a354..9cfe890 100644 ---- a/lib/Sabberworm/CSS/Value/Size.php -+++ b/lib/Sabberworm/CSS/Value/Size.php -@@ -37,27 +37,15 @@ class Size extends PrimitiveValue { - } - } - -- $sParsedUnit = ''; -- $iOffset = 0; -- while (true) { -- $sChar = $oParserState->peek(1, $iOffset); -- $iPeek = ord($sChar); -- -- // Ranges: a-z A-Z 0-9 % -- if (($iPeek >= 97 && $iPeek <= 122) || -- ($iPeek >= 65 && $iPeek <= 90) || -- ($iPeek >= 48 && $iPeek <= 57) || -- ($iPeek === 37)) { -- $sParsedUnit .= $sChar; -- $iOffset++; -- } else { -- break; -- } -- } -- - $sUnit = null; -+ $sParsedUnit = null; - $aSizeUnits = self::getSizeUnits(); - -+ $iMaxSizeUnitLength = max(array_keys($aSizeUnits)); -+ if ( preg_match( '/^[a-zA-Z0-9%]+/', $oParserState->peek($iMaxSizeUnitLength), $matches ) ) { -+ $sParsedUnit = $matches[0]; -+ } -+ - foreach($aSizeUnits as $iLength => $aValues) { - $sKey = strtolower($oParserState->peek($iLength)); - if(array_key_exists($sKey, $aValues)) { --- -2.25.1 - - -From b19d79be31b8b71300182f6c10a326386ec65d05 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon -Date: Mon, 11 May 2020 17:53:50 -0400 -Subject: [PATCH 6/7] Refactor size unit parsing logic - ---- - lib/Sabberworm/CSS/Value/Size.php | 23 +++++++++-------------- - 1 file changed, 9 insertions(+), 14 deletions(-) - -diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php -index 9cfe890..26e3eb1 100644 ---- a/lib/Sabberworm/CSS/Value/Size.php -+++ b/lib/Sabberworm/CSS/Value/Size.php -@@ -38,26 +38,21 @@ class Size extends PrimitiveValue { - } - - $sUnit = null; -- $sParsedUnit = null; - $aSizeUnits = self::getSizeUnits(); -- - $iMaxSizeUnitLength = max(array_keys($aSizeUnits)); -+ - if ( preg_match( '/^[a-zA-Z0-9%]+/', $oParserState->peek($iMaxSizeUnitLength), $matches ) ) { -- $sParsedUnit = $matches[0]; -- } -+ $sUnit = strtolower($matches[0]); -+ $iUnitLength = strlen($sUnit); - -- foreach($aSizeUnits as $iLength => $aValues) { -- $sKey = strtolower($oParserState->peek($iLength)); -- if(array_key_exists($sKey, $aValues)) { -- if (strtolower($sParsedUnit) !== $sKey) { -- throw new UnexpectedTokenException('Unit', $sParsedUnit, 'identifier', $oParserState->currentLine()); -- } -- if (($sUnit = $aValues[$sKey]) !== null) { -- $oParserState->consume($iLength); -- break; -- } -+ if (isset($aSizeUnits[$iUnitLength][$sUnit])) { -+ $sUnit = $aSizeUnits[$iUnitLength][$sUnit]; -+ $oParserState->consume($iUnitLength); -+ } else { -+ throw new UnexpectedTokenException('Unit', $sUnit, 'identifier', $oParserState->currentLine()); - } - } -+ - return new Size(floatval($sSize), $sUnit, $bIsColorComponent, $oParserState->currentLine()); - } - --- -2.25.1 - - -From 9862b6087d0f5c8c8406d8e3033fde5352ad0c90 Mon Sep 17 00:00:00 2001 -From: Pierre Gordon <16200219+pierlon@users.noreply.github.com> -Date: Mon, 11 May 2020 19:22:45 -0400 -Subject: [PATCH 7/7] Match percent symbol or alphanumeric text - -Co-authored-by: Weston Ruter ---- - lib/Sabberworm/CSS/Value/Size.php | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/lib/Sabberworm/CSS/Value/Size.php b/lib/Sabberworm/CSS/Value/Size.php -index 26e3eb1..cd1a213 100644 ---- a/lib/Sabberworm/CSS/Value/Size.php -+++ b/lib/Sabberworm/CSS/Value/Size.php -@@ -41,7 +41,7 @@ class Size extends PrimitiveValue { - $aSizeUnits = self::getSizeUnits(); - $iMaxSizeUnitLength = max(array_keys($aSizeUnits)); - -- if ( preg_match( '/^[a-zA-Z0-9%]+/', $oParserState->peek($iMaxSizeUnitLength), $matches ) ) { -+ if ( preg_match( '/^(%|[a-zA-Z0-9]+)/', $oParserState->peek($iMaxSizeUnitLength), $matches ) ) { - $sUnit = strtolower($matches[0]); - $iUnitLength = strlen($sUnit); - --- -2.25.1 - diff --git a/web-stories.php b/web-stories.php index 563b6a81dc54..f260337d0083 100644 --- a/web-stories.php +++ b/web-stories.php @@ -42,7 +42,7 @@ define( 'WEBSTORIES_VERSION', '1.1.0' ); define( 'WEBSTORIES_DB_VERSION', '3.0.2' ); -define( 'WEBSTORIES_AMP_VERSION', '2.0.4' ); // Version of the AMP library included in the plugin. +define( 'WEBSTORIES_AMP_VERSION', '2.0.5' ); // Version of the AMP library included in the plugin. define( 'WEBSTORIES_PLUGIN_FILE', __FILE__ ); define( 'WEBSTORIES_PLUGIN_DIR_PATH', plugin_dir_path( WEBSTORIES_PLUGIN_FILE ) ); define( 'WEBSTORIES_PLUGIN_DIR_URL', plugin_dir_url( WEBSTORIES_PLUGIN_FILE ) );