Skip to content

Commit 81afe9f

Browse files
ebraminioMatmaRex
authored andcommitted
Flip calc() in four value notation
Port I46dab696def51928effe7c093b863e6726c39f49 to php-cssjanus and update test cases to 2.2.0. Bug: T369553 Change-Id: I62cdcf0e2aa22ee5a2c0e325fdd412b71b3904ad
1 parent 3adea97 commit 81afe9f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/CSSJanus.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ private static function buildPatterns() {
9393
$patterns['ident'] = "-?{$patterns['nmstart']}{$patterns['nmchar']}*";
9494
$patterns['quantity'] = "{$patterns['num']}(?:\s*{$patterns['unit']}|{$patterns['ident']})?";
9595
$patterns['possibly_negative_quantity'] = "((?:-?{$patterns['quantity']})|(?:inherit|auto))";
96+
$patterns['possibly_negative_simple_quantity'] = "(?:-?{$patterns['num']}(?:\s*{$patterns['unit']})?)";
97+
$patterns['math_operator'] = '(?:\+|\-|\*|\/)';
98+
$patterns['allowed_chars'] = '(?:\(|\)|\t| )';
99+
$patterns['calc_equation'] = "(?:{$patterns['allowed_chars']}|{$patterns['possibly_negative_simple_quantity']}|{$patterns['math_operator']}){3,}";
100+
$patterns['calc'] = "(?:calc\((?:{$patterns['calc_equation']})\))";
101+
$patterns['possibly_negative_quantity_calc'] = "((?:-?{$patterns['quantity']})|(?:inherit|auto)|{$patterns['calc']})";
96102
$patterns['color'] = "(#?{$patterns['nmchar']}+|(?:rgba?|hsla?)\([ \d.,%-]+\))";
97103
// Use "*+" instead of "*?" to avoid reaching the backtracking limit.
98104
// <https://phabricator.wikimedia.org/T326481>, <https://phabricator.wikimedia.org/T215746#4944830>.
@@ -113,7 +119,7 @@ private static function buildPatterns() {
113119
$patterns['cursor_east'] = "/{$patterns['lookbehind_not_letter']}([ns]?)e-resize/";
114120
$patterns['cursor_west'] = "/{$patterns['lookbehind_not_letter']}([ns]?)w-resize/";
115121
$patterns['four_notation_quantity_props'] = "((?:margin|padding|border-width)\s*:\s*)";
116-
$patterns['four_notation_quantity'] = "/{$patterns['four_notation_quantity_props']}{$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}(\s+){$patterns['possibly_negative_quantity']}{$patterns['suffix']}/i";
122+
$patterns['four_notation_quantity'] = "/{$patterns['four_notation_quantity_props']}{$patterns['possibly_negative_quantity_calc']}(\s+){$patterns['possibly_negative_quantity_calc']}(\s+){$patterns['possibly_negative_quantity_calc']}(\s+){$patterns['possibly_negative_quantity_calc']}{$patterns['suffix']}/i";
117123
$patterns['four_notation_color'] = "/((?:-color|border-style)\s*:\s*){$patterns['color']}(\s+){$patterns['color']}(\s+){$patterns['color']}(\s+){$patterns['color']}{$patterns['suffix']}/i";
118124
// border-radius: <length or percentage>{1,4} [optional: / <length or percentage>{1,4} ]
119125
$patterns['border_radius'] = '/(border-radius\s*:\s*)' . $patterns['possibly_negative_quantity']

test/suites/CSSJanusTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ public function testTransform( $input, $args, $output, $name ) {
6262
protected static function getSpec() {
6363
static $json;
6464
if ( $json == null ) {
65-
$version = '2.1.0';
65+
$version = '2.2.0';
6666
$dir = dirname( __DIR__ );
6767
$file = "$dir/data-v$version.json";
6868
if ( !is_readable( $file ) ) {
6969
array_map( 'unlink', glob( "$dir/data-v*.json" ) );
7070
$json = file_get_contents(
71-
"https://raw.githubusercontent.com/cssjanus/cssjanus/v$version/test/data.json"
71+
"https://raw.githubusercontent.com/wikimedia/node-cssjanus/v$version/test/data.json"
7272
);
7373
if ( $json === false ) {
7474
throw new Exception( 'Failed to fetch data' );

0 commit comments

Comments
 (0)