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

Regex containing "/" (backslash) fails starting from v0.6 #145

Closed
RonaldTreur opened this issue Jan 18, 2016 · 7 comments
Closed

Regex containing "/" (backslash) fails starting from v0.6 #145

RonaldTreur opened this issue Jan 18, 2016 · 7 comments

Comments

@RonaldTreur
Copy link

Hi guys,

Happy to see this project continues with a new crew. Thanks you guys and good luck! And of course a big thanks to @ericclemmons for initiating this project!

As for my issue:

I used to work with 0.5.9 and that worked great. Today I finally got around to update to v1.0.1, but unfortunately that didn't produce the same result. A regular expression contained in the HTML (ng-pattern attribute) suddenly caused the browser to throw up. I backtracked a bit and noticed this started with v0.6.

This is the regex in the source HTML file:

/^(((\+[1-9][0-9])|(00[1-9][0-9]))[0-9]{7,11})|((((01|02|03|04|05|07|08)[0-9])|(06[1-9]))[0-9]{7})$/

This is what v0.5.9 produced (inside the $templateCache.put)

/^(((\\+[1-9][0-9])|(00[1-9][0-9]))[0-9]{7,11})|((((01|02|03|04|05|07|08)[0-9])|(06[1-9]))[0-9]{7})$/

This is what v0.6.0 (and higher) produces (inside the $templateCache.put)

/^(((\+[1-9][0-9])|(00[1-9][0-9]))[0-9]{7,11})|((((01|02|03|04|05|07|08)[0-9])|(06[1-9]))[0-9]{7})$/

The only difference is the backslash character (@ position 6) is no longer being escaped properly. Which means the end result is (in the DOM):

/^(((+[1-9][0-9])|(00[1-9][0-9]))[0-9]{7,11})|((((01|02|03|04|05|07|08)[0-9])|(06[1-9]))[0-9]{7})$/

which (correctly) results in the following error:

SyntaxError: Invalid regular expression: /^(((+[1-9][0-9])|(00[1-9][0-9]))[0-9]{7,11})|((((01|02|03|04|05|07|08)[0-9])|(06[1-9]))[0-9]{7})$/: Nothing to repeat
    at new RegExp (native)

Any idea where this went wrong? When I have more time I can try to figure it out myself, but for the moment I'm back at v0.5.9.

@underscorebrody
Copy link
Collaborator

Thanks for the report! I have an idea where the problem might be, we modified the way we stringify the lines and it looks like something in there is causing a problem in this case. I'll take a look at it now.

@underscorebrody
Copy link
Collaborator

@RonaldTreur mind taking a quick look at #146 ?

@RonaldTreur
Copy link
Author

Tested it and works like a charm! Good to go ;-)

@evilaliv3
Copy link
Contributor

i'm having the same issue but in a different context.

the current stringify function fails in case a user uses in its code escaped quotes.

this happens for example if in your code you have something like:

<input name="password" class="form-control" data-ng-model="admin_password" type="password" data-ng-attr-placeholder="{{'Enter a password for the user \'admin\'' | translate}}" required>

i've already tried using:

    options: {
      quotes: 'single'
    }

but obviously in this context both single and double quotes are used so switching is making other things failing.

my suggestion is in the meantime to simply revert d2dc35c and then iterate on this issue until a stable solution is found.

@evilaliv3
Copy link
Contributor

I took care to retest the fix in #146 on GlobaLeaks that is using grunt-angular-templates extensively but some pages are still failing.

I will keep you posted with the details to be reused in the unit testing.

evilaliv3 added a commit to globaleaks/globaleaks-whistleblowing-software that referenced this issue Jan 19, 2016
@underscorebrody
Copy link
Collaborator

@evilaliv3 What do you think about #148 ?

@evilaliv3
Copy link
Contributor

going to try it now

evilaliv3 added a commit to globaleaks/globaleaks-whistleblowing-software that referenced this issue Jan 26, 2016
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

3 participants