Skip to content

fix(translate): escape special character % to prevent crash #138

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xavierdeneux
Copy link

@xavierdeneux xavierdeneux commented Feb 18, 2025

🤔 Why?

I saw an error with one of my preview for EPG and the root cause was the title of the box contained the "%" chars.
Because of this char, the sprintf command failed.

t('my_translation_string%') does not work
(In fact, in my original case, the "translation string" is not really a translation key but an already translated key like t('Mon super programme 100% cool')

image

💻 How?

Escape the "%" chars to prevent sprintf command to crash.

const translatedResult = sprintf(translation, { ...data, ...i18nNames, number });
// escape special characters (% for now)
const translationValues = _mapValues({ ...data, ...i18nNames, number }, value => {
if (value) {
Copy link

@qtomasicchio qtomasicchio Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the unit test, value can be a number. We should probably check that we have a string, what do you think?

Suggested change
if (value) {
if (typeof value === 'string') {

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