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

Fix bug 1563677: Escape selectors in data-expression attributes #1334

Merged
merged 1 commit into from
Jul 5, 2019

Conversation

mathjazz
Copy link
Collaborator

@mathjazz mathjazz commented Jul 5, 2019

Translating a string like this in the rich editor is not possible - it results in an Expected literal error upon saving:

number =
    { NUMBER($var, type: "ordinal") ->
        [1] first
        [one] { $var }st
       *[other] { $var }nd
    }

What's going on?

Pontoon doesn't show selectors (in this case NUMBER($var, type: "ordinal")) in the rich editor, but still stores them in DOM to help with serialization. Specifically, it naïvely puts them in data-expression attributes, without any escaping.

So when the selector contains quotes, like in our example, content gets stripped upon serialization, resulting in the above error. The serialized string looks like this:

number =
    { NUMBER($var, type:  ->
        [1] first
        [one] { $var }st
       *[other] { $var }nd
    }

A test case:
https://github.com/mozilla-l10n/pontoon-ftl/blob/master/en-US/demo.ftl#L53

@mathjazz mathjazz force-pushed the bug-1563677-escape-selectors branch from f202c2a to 894f5fa Compare July 5, 2019 10:12
@jamesking
Copy link

My colleague @elisehein would be best placed to do a review :)

Copy link

@elisehein elisehein left a comment

Choose a reason for hiding this comment

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

Thank you for this, it looks good to me! Tested and entering a translation with an ordinal number selector works as expected 👍

@mathjazz
Copy link
Collaborator Author

mathjazz commented Jul 5, 2019

Thanks for the review, I'm glad this is helpful! :)

@mathjazz mathjazz merged commit adb45d2 into mozilla:master Jul 5, 2019
@mathjazz mathjazz deleted the bug-1563677-escape-selectors branch July 5, 2019 12:04
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.

3 participants