From 0449591dc6e8856137f03b9e34f2d75c4c4f14c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 27 Feb 2024 13:32:31 +0100 Subject: [PATCH] Adjust for renamed scope condition field property (#2179) --- src/App.php | 2 +- src/Behat/Context.php | 2 +- src/Form/Control/ScopeBuilder.php | 13 +++++++------ src/Js/JsExpression.php | 2 +- tests/DemosTest.php | 6 +++--- tests/JsTest.php | 4 ++-- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/App.php b/src/App.php index 701828474b..e5d093ab06 100644 --- a/src/App.php +++ b/src/App.php @@ -1112,7 +1112,7 @@ public function encodeJson($data, bool $forceObject = false): string // IMPORTANT: always convert large integers to string, otherwise numbers can be rounded by JS // replace large JSON integers only, do not replace anything in JSON/JS strings - $json = preg_replace_callback('~"(?:[^"\\\\]+|\\\\.)*+"\K|\'(?:[^\'\\\\]+|\\\\.)*+\'\K' + $json = preg_replace_callback('~"(?:[^"\\\]+|\\\.)*+"\K|\'(?:[^\'\\\]+|\\\.)*+\'\K' . '|(?:^|[{\[,:])[ \n\r\t]*\K-?[1-9]\d{15,}(?=[ \n\r\t]*(?:$|[}\],:]))~s', static function ($matches) { if ($matches[0] === '' || abs((int) $matches[0]) < (2 ** 53)) { return $matches[0]; diff --git a/src/Behat/Context.php b/src/Behat/Context.php index f1f3aceb5b..312ad89a52 100644 --- a/src/Behat/Context.php +++ b/src/Behat/Context.php @@ -272,7 +272,7 @@ protected function findElement(?NodeElement $context, string $selector): NodeEle protected function unquoteStepArgument(string $argument): string { // copied from https://github.com/Behat/MinkExtension/blob/v2.2/src/Behat/MinkExtension/Context/MinkContext.php#L567 - return str_replace('\\"', '"', $argument); + return str_replace('\"', '"', $argument); } /** diff --git a/src/Form/Control/ScopeBuilder.php b/src/Form/Control/ScopeBuilder.php index 52fb600481..33bab27b14 100644 --- a/src/Form/Control/ScopeBuilder.php +++ b/src/Form/Control/ScopeBuilder.php @@ -614,12 +614,13 @@ public function scopeToQuery(Scope\AbstractScope $scope, array $inputsMap = []): */ public function conditionToQuery(Condition $condition, array $inputsMap = []): array { - if (is_string($condition->key)) { - $rule = $condition->key; - } elseif ($condition->key instanceof Field) { - $rule = $condition->key->shortName; + if (is_string($condition->field)) { + $rule = $condition->field; + } elseif ($condition->field instanceof Field) { + $rule = $condition->field->shortName; } else { - throw new Exception('Unsupported scope key: ' . gettype($condition->key)); + throw (new Exception('Unsupported scope field type')) + ->addMoreInfo('field', $condition->field); } $operator = $condition->operator; @@ -686,7 +687,7 @@ protected function getConditionOption(string $type, $value, Condition $condition $option = null; switch ($type) { case 'lookup': - $condField = $condition->getModel()->getField($condition->key); + $condField = $condition->getModel()->getField($condition->field); $reference = $condField->getReference(); $model = $reference->refModel($condField->getOwner()); $fieldName = $reference->getTheirFieldName($model); diff --git a/src/Js/JsExpression.php b/src/Js/JsExpression.php index 89993f1b19..bc34cbe046 100644 --- a/src/Js/JsExpression.php +++ b/src/Js/JsExpression.php @@ -97,7 +97,7 @@ protected function _jsEncode($value): string } } elseif (is_string($value)) { $res = json_encode($value, \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR); - $res = '\'' . str_replace('\'', '\\\'', str_replace('\\"', '"', substr($res, 1, -1))) . '\''; + $res = '\'' . str_replace('\'', '\\\'', str_replace('\"', '"', substr($res, 1, -1))) . '\''; } elseif (is_bool($value)) { $res = $value ? 'true' : 'false'; } elseif (is_int($value)) { diff --git a/tests/DemosTest.php b/tests/DemosTest.php index 21107cdc6a..db672b22c2 100644 --- a/tests/DemosTest.php +++ b/tests/DemosTest.php @@ -38,7 +38,7 @@ class DemosTest extends TestCase protected static string $regexJson = '~^(?\s*(?: (?-?(?=[1-9]|0(?!\d))\d+(\.\d+)?(E[+-]?\d+)?) |(?true|false|null) - |(?"([^"\\\\]*|\\\\["\\\\bfnrt/]|\\\\u[0-9a-f]{4})*") + |(?"([^"\\\]*|\\\["\\\bfnrt/]|\\\u[0-9a-f]{4})*") |(?\[(?:(?&json)(?:,(?&json))*|\s*)\]) |(?\{(?:(?\s*(?&string)\s*:(?&json))(?:,(?&pair))*|\s*)\}) )\s*)$~six'; @@ -417,7 +417,7 @@ public function testDemoJsonResponse(string $path, string $expectedExceptionMess self::assertSame('application/json', preg_replace('~;\s*charset=.+$~', '', $response->getHeaderLine('Content-Type'))); $responseBodyStr = $response->getBody()->getContents(); self::assertMatchesRegularExpression(self::$regexJson, $responseBodyStr); - self::assertStringNotContainsString(preg_replace('~.+\\\\~', '', UnhandledCallbackExceptionError::class), $responseBodyStr); + self::assertStringNotContainsString(preg_replace('~.+\\\~', '', UnhandledCallbackExceptionError::class), $responseBodyStr); if ($expectedExceptionMessage !== null) { self::assertStringContainsString($expectedExceptionMessage, $responseBodyStr); } @@ -498,7 +498,7 @@ public function testDemoCallbackError(string $path, string $expectedExceptionMes self::assertSame('no-store', $response->getHeaderLine('Cache-Control')); $responseBodyStr = $response->getBody()->getContents(); self::assertMatchesRegularExpression(self::$regexHtml, $responseBodyStr); - self::assertStringNotContainsString(preg_replace('~.+\\\\~', '', UnhandledCallbackExceptionError::class), $responseBodyStr); + self::assertStringNotContainsString(preg_replace('~.+\\\~', '', UnhandledCallbackExceptionError::class), $responseBodyStr); self::assertStringContainsString($expectedExceptionMessage, $responseBodyStr); } diff --git a/tests/JsTest.php b/tests/JsTest.php index 90cbc60e22..6e4cd50f52 100644 --- a/tests/JsTest.php +++ b/tests/JsTest.php @@ -29,7 +29,7 @@ public function testBasicExpressions(): void public function testStrings(): void { self::assertSame('\'\\\'\', \'"\', \'\n\'', (new JsExpression('[], [], []', ['\'', '"', "\n"]))->jsRender()); - self::assertSame('\'\\\'a"b\\\\\\\'c\\\\" \\\'"\'', (new JsExpression('[]', ['\'a"b\\\'c\\" \'"']))->jsRender()); + self::assertSame('\'\\\'a"b\\\\\\\'c\\\" \\\'"\'', (new JsExpression('[]', ['\'a"b\\\'c\" \'"']))->jsRender()); } public function testNumbers(): void @@ -56,7 +56,7 @@ public function testNumbers(): void ] as [$in, $expected]) { $jsRendered = (new JsExpression('[]', [$in]))->jsRender(); if (substr($jsRendered, 0, 1) === '\'') { - $jsRendered = '"' . str_replace('"', '\\"', substr($jsRendered, 1, -1)) . '"'; + $jsRendered = '"' . str_replace('"', '\"', substr($jsRendered, 1, -1)) . '"'; } self::assertSame($expected, $jsRendered);