diff --git a/projects/packages/jetpack-mu-wpcom/changelog/fix-address_lessc_preprocessor_issues b/projects/packages/jetpack-mu-wpcom/changelog/fix-address_lessc_preprocessor_issues new file mode 100644 index 0000000000000..f31b2c0dded7a --- /dev/null +++ b/projects/packages/jetpack-mu-wpcom/changelog/fix-address_lessc_preprocessor_issues @@ -0,0 +1,4 @@ +Significance: patch +Type: fixed + +LESS: Clean up various issues in legacy library. diff --git a/projects/packages/jetpack-mu-wpcom/src/features/custom-css/custom-css/preprocessors/lessc.inc.php b/projects/packages/jetpack-mu-wpcom/src/features/custom-css/custom-css/preprocessors/lessc.inc.php index 644294af603f6..8bd348ed493fe 100644 --- a/projects/packages/jetpack-mu-wpcom/src/features/custom-css/custom-css/preprocessors/lessc.inc.php +++ b/projects/packages/jetpack-mu-wpcom/src/features/custom-css/custom-css/preprocessors/lessc.inc.php @@ -36,6 +36,7 @@ * The `lessc_formatter` takes a CSS tree, and dumps it to a formatted string, * handling things like indentation. */ +#[\AllowDynamicProperties] class lessc { static public $VERSION = "v0.5.0"; @@ -662,7 +663,7 @@ protected function zipSetArgs($args, $orderedValues, $keywordValues) { // check for a rest $last = end($args); - if ($last[0] == "rest") { + if (isset($last[0]) && $last[0] == "rest") { $argsCount = is_countable( $args ) ? count( $args ) : 0; $rest = array_slice($orderedValues, $argsCount - 1); $this->set($last[1], $this->reduce(array("list", " ", $rest))); @@ -1269,7 +1270,7 @@ protected function lib_contrast($args) { protected function lib_luma($color) { $color = $this->coerceColor($color); - return (0.2126 * $color[0] / 255) + (0.7152 * $color[1] / 255) + (0.0722 * $color[2] / 255); + return (0.2126 * $color[1] / 255) + (0.7152 * $color[2] / 255) + (0.0722 * $color[3] / 255); } @@ -1569,7 +1570,7 @@ protected function coerceColor($value) { $width = strlen($colorStr) == 3 ? 16 : 256; for ($i = 3; $i > 0; $i--) { // 3 2 1 - $t = $num % $width; + $t = (int) $num % $width; $num /= $width; $c[$i] = $t * (256/$width) + $t * floor(16/$width); @@ -2273,6 +2274,7 @@ public static function cexecute($in, $force = false, $less = null) { // responsible for taking a string of LESS code and converting it into a // syntax tree +#[\AllowDynamicProperties] class lessc_parser { static protected $nextBlockId = 0; // used to uniquely identify blocks @@ -3500,7 +3502,7 @@ protected function match($regex, &$out, $eatWhitespace = null) { if ($eatWhitespace === null) $eatWhitespace = $this->eatWhiteDefault; $r = '/'.$regex.($eatWhitespace && !$this->writeComments ? '\s*' : '').'/Ais'; - if (preg_match($r, $this->buffer, $out, null, $this->count)) { + if (preg_match($r, $this->buffer, $out, 0, $this->count)) { $this->count += strlen($out[0]); if ($eatWhitespace && $this->writeComments) $this->whitespace(); return true; @@ -3531,7 +3533,7 @@ protected function whitespace() { protected function peek($regex, &$out = null, $from=null) { if (is_null($from)) $from = $this->count; $r = '/'.$regex.'/Ais'; - $result = preg_match($r, $this->buffer, $out, null, $from); + $result = preg_match($r, $this->buffer, $out, 0, $from); return $result; } @@ -3754,6 +3756,7 @@ public function block($block) { } } +#[\AllowDynamicProperties] class lessc_formatter_compressed extends lessc_formatter_classic { public $disableSingle = true; public $open = "{";