preserve accents in fields containing Twig expr. using unicode #2279
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a field contain accentuated characters, reduce the risk of messing with it by passing unicode characters unescaped.
Twig will deal with them. And fewer backslash-escaping problems will arise.
In order to allow blueprints fields to contain Twig expression,
processString()
is used.Ideally it would deal with object/array by processing (= Twig-rendering) inner elements recursively.
But what it instead does, in order to flatten the value, is
json_decode(Twig::render(json_encode($value)))
If someone use such a field value:
{{ url.uri ~ 'é' }}
, it will be transformed to{{ url.uri ~ '\u00e9' }}
.And
Grav\Common\Twig::processString
calling$this->twig->render()
with that string returnslocalhostu00e9
whose accent won't be restored afterjson_decode()
.I don't know why Twig calls seems broken. But using at least
JSON_UNESCAPED_UNICODE
is a safe enough solution that quickly reduces problem's surface.