Skip to content

Commit

Permalink
Merge branch 'v3' of https://github.com/craftcms/cms into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/fields/Table.php
  • Loading branch information
brandonkelly committed Mar 17, 2023
2 parents 5d6e77d + e2f7e7b commit 52bd161
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

- Input autofocussing has been reintroduced thorughout the control panel. ([#12921](https://github.com/craftcms/cms/discussions/12921))
- The `|json_encode` Twig filter now calls `craft\helpers\Json::encode()` internally, improving error handling. ([#12919](https://github.com/craftcms/cms/issues/12919))
- `craft\helpers\Json::encode()` no longer sets the `JSON_UNESCAPED_SLASHES` flag by default.
- Fixed a JavaScript error that occurred when resolving an asset move conflict. ([#12920](https://github.com/craftcms/cms/issues/12920))
- Fixed an error that could occur when rebuilding the project config, if there were any custom source definitions for element types that weren’t Composer-installed. ([#12881](https://github.com/craftcms/cms/issues/12881))
- Fixed an XSS vulnerability.

## 4.4.3 - 2023-03-16

Expand Down
6 changes: 3 additions & 3 deletions src/fields/Matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ public function getSettingsHtml(): ?string
$placeholderKey = StringHelper::randomString(10);
$view->registerJs(
'new Craft.MatrixConfigurator(' .
Json::encode($fieldTypeInfo, JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($view->getNamespace(), JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($fieldTypeInfo) . ', ' .
Json::encode($view->getNamespace()) . ', ' .
Json::encode($view->namespaceInputName("blockTypes[__BLOCK_TYPE_{$placeholderKey}__][fields][__FIELD_{$placeholderKey}__][typesettings]")) . ', ' .
Json::encode($placeholderKey) .
');'
Expand Down Expand Up @@ -721,7 +721,7 @@ protected function inputHtml(mixed $value, ?ElementInterface $element = null): s

$js = 'var matrixInput = new Craft.MatrixInput(' .
'"' . $view->namespaceInputId($id) . '", ' .
Json::encode($blockTypeInfo, JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($blockTypeInfo) . ', ' .
'"' . $view->namespaceInputName($this->handle) . '", ' .
Json::encode($settings) .
');';
Expand Down
14 changes: 7 additions & 7 deletions src/fields/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,13 +310,13 @@ public function getSettingsHtml(): ?string
$view->registerAssetBundle(TimepickerAsset::class);
$view->registerAssetBundle(TableSettingsAsset::class);
$view->registerJs('new Craft.TableFieldSettings(' .
Json::encode($view->namespaceInputName('columns'), JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($view->namespaceInputName('defaults'), JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($this->columns, JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($this->defaults ?? [], JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($columnSettings, JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($dropdownSettingsHtml, JSON_UNESCAPED_UNICODE) . ', ' .
Json::encode($dropdownSettingsCols, JSON_UNESCAPED_UNICODE) .
Json::encode($view->namespaceInputName('columns')) . ', ' .
Json::encode($view->namespaceInputName('defaults')) . ', ' .
Json::encode($this->columns) . ', ' .
Json::encode($this->defaults ?? []) . ', ' .
Json::encode($columnSettings) . ', ' .
Json::encode($dropdownSettingsHtml) . ', ' .
Json::encode($dropdownSettingsCols) .
');');

$columnsField = $view->renderTemplate('_components/fieldtypes/Table/columntable.twig', [
Expand Down
9 changes: 9 additions & 0 deletions src/helpers/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public static function isJsonObject(string $str): bool
return (bool)preg_match('/^(?:\{.*\}|\[.*\])$/s', $str);
}

/**
* @inheritdoc
* @param int $options The encoding options. `JSON_UNESCAPED_UNICODE` is used by default.
*/
public static function encode($value, $options = JSON_UNESCAPED_UNICODE)
{
return parent::encode($value, $options);
}

/**
* Decodes the given JSON string into a PHP data structure, only if the string is valid JSON.
*
Expand Down
2 changes: 1 addition & 1 deletion src/web/assets/cp/CpAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function registerAssetFiles($view): void
}

// Define the Craft object
$craftJson = Json::encode($this->_craftData(), JSON_UNESCAPED_UNICODE);
$craftJson = Json::encode($this->_craftData());
$js = <<<JS
window.Craft = $craftJson;
JS;
Expand Down

0 comments on commit 52bd161

Please sign in to comment.