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

Ternary operator parsing produces some false results #74

Open
phw opened this issue Mar 29, 2016 · 2 comments
Open

Ternary operator parsing produces some false results #74

phw opened this issue Mar 29, 2016 · 2 comments

Comments

@phw
Copy link
Contributor

phw commented Mar 29, 2016

With the patch from PR #69 the code snippet below will generate both the false translation keys active and non-active in addition to the correct one STATE_LABEL.

<a ng-class=" state==3 ? 'active': 'non-active'">
    <span>3</span> {{'STATE_LABEL' | translate}}
</a>

If I disable the HtmlFilterTernary regex (by commenting it out in tasks/angular-translate.js the extraction works as expected (only extracting STATE_LABEL).

@rgant
Copy link

rgant commented Sep 13, 2016

I believe that this pattern for HtmlFilterTernary would work better:

\s*(?:::)?([^?|}]*\?[^:]*:[^|}]*)\s*\|\s*translate(:.*?)?\s*

The change is in the first character class which was [^?]* (match any characters not ?) to [^?|}]* (match any characters not ?, |, or }). This prevents the match from crossing too many other interpolation sequences.

@rgant
Copy link

rgant commented Oct 31, 2016

In the meantime, adding a comment like this will help to prevent this regex from matching incorrectly. I inserted it after a ternary before the next translate.

<!-- Prevent grunt-angular-translate from incorrectly matching: ?|: -->

Edited: with a more effective comment.

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

No branches or pull requests

2 participants