Exclude I18n reserved keys from html escaping #1953
Merged
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.
What are you trying to accomplish?
With html translation keys, reserved keys are currently being made html safe, thus converting values like
true
to"true"
. This is disabling some of these keys.What approach did you choose and why?
The existing code tries to match reserved keys using the
::I18n.reserved_keys_pattern
, however they will never match, as the pattern is expecting interpolated strings with the translation value. It will match%{raise}
, but notraise
, which is what we want. So these reserved key values are all subsequently html escaped.This PR uses the
I18n::RESERVED_KEYS
constant directly, and excludes those keys from options that will be considered for escaping.Anything you want to highlight for special attention from reviewers?
The key that I chose for testing was
:raise
. This meant that I needed a missing translation, so I've added another locale to theI18n.available_locales
. This also matched the original scenario in my app that caused me to discover the issue.