Skip to content

Commit

Permalink
Adjust for renamed scope condition field property (#2179)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Feb 27, 2024
1 parent 67bc0c6 commit 0449591
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion src/Behat/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions src/Form/Control/ScopeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Js/JsExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions tests/DemosTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class DemosTest extends TestCase
protected static string $regexJson = '~^(?<json>\s*(?:
(?<number>-?(?=[1-9]|0(?!\d))\d+(\.\d+)?(E[+-]?\d+)?)
|(?<boolean>true|false|null)
|(?<string>"([^"\\\\]*|\\\\["\\\\bfnrt/]|\\\\u[0-9a-f]{4})*")
|(?<string>"([^"\\\]*|\\\["\\\bfnrt/]|\\\u[0-9a-f]{4})*")
|(?<array>\[(?:(?&json)(?:,(?&json))*|\s*)\])
|(?<object>\{(?:(?<pair>\s*(?&string)\s*:(?&json))(?:,(?&pair))*|\s*)\})
)\s*)$~six';
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/JsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down

0 comments on commit 0449591

Please sign in to comment.