Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preserve accents in fields containing Twig expr. using unicode #2279

Merged
merged 1 commit into from
Jan 9, 2019

Conversation

drzraf
Copy link
Contributor

@drzraf drzraf commented Dec 1, 2018

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 returns localhostu00e9 whose accent won't be restored after json_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.

When a fields 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.
@rhukster rhukster merged commit f136387 into getgrav:develop Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants