Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

ngSanitize syntax error in Chrome/IE11 #11598

Closed
luanshixia opened this issue Apr 15, 2015 · 11 comments
Closed

ngSanitize syntax error in Chrome/IE11 #11598

luanshixia opened this issue Apr 15, 2015 · 11 comments

Comments

@luanshixia
Copy link
Contributor

[Message] Uncaught SyntaxError: Invalid regular expression: missing /
[File] angular-sanitize.js, Line: 619, Column: 98
[Version] 1.3.15

This error is not observed in 1.2.x.

@Narretz
Copy link
Contributor

Narretz commented Apr 15, 2015

Can you please provide a runnable code example that shows this error? (plnkr.co etc.) This is not enough information to act on this issue.

@luanshixia
Copy link
Contributor Author

Interestingly, this error is only observable with the unminified angular-sanitize.js. When using angular-sanitize.min.js it is OK.

<!DOCTYPE html>
<html>
<head>
    <title>Angular Bug</title>
</head>
<body>

    <script type="text/javascript" src="angular.js"></script>
    <script type="text/javascript" src="angular-sanitize.js"></script>
</body>
</html>

Open this html in Chrome, you can find error in the console.

@pkozlowski-opensource
Copy link
Member

I can't reproduce: http://plnkr.co/edit/PaSOmNTTeXG8yq8aZfl3?p=preview

Maybe your file got messed up during the download process? Edited by accident? Or maybe you've got a particular Chrome extension installed?

In any case I can't reproduce it with a simple plunker.

@luanshixia
Copy link
Contributor Author

In the uncompressed file, there is a regex:

/((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"”’]/

But in the min.js file, this regex is:

/((ftp|https?):\/\/|(www\.)|(mailto:)?[A-Za-z0-9._%+-]+@)\S*[^\s.;,(){}<>"\u201d\u2019]/

I guess there must be something wrong.

@pkozlowski-opensource
Copy link
Member

@luanshixia yes, minification process seems to change some quote literals to their \u equivalents. Bot both regexps are still valid (at least syntactically).

I guess there must be something wrong.

Might be, but we still need a reproduce scenario. I've linked a simple plunker that represents what you've been describing (or at least my understanding of it!) and doesn't throw any errors?

Could you please modify this plunk to expose the error?

@luanshixia
Copy link
Contributor Author

@pkozlowski-opensource just save the plunker sample to local hard drive and run. You will see that the filter does not work. At least on my machine.

@pkozlowski-opensource
Copy link
Member

@luanshixia it still works if saved to a local file (I really don't see a reason to behave differently while saved to a local file). Does the plunker I've linked works for you?

At least on my machine.

This is why I was suggesting issues linked to your local env:

Maybe your file got messed up during the download process? Edited by accident? Or maybe you've got a particular Chrome extension installed?

@luanshixia
Copy link
Contributor Author

@pkozlowski-opensource the online sample works fine. Maybe it does have something to do with my environment, specifically the locale of Chrome. When opening/requesting the file in my Chrome (Simplified Chinese), I see messed up code in that regex. It is OK if opened in Sumlime Text.

If this is true, is it possible to escape the quote marks in the source, just like the minified js?

@pkozlowski-opensource
Copy link
Member

@luanshixia I don't think it is linked to the locale of Chrome since it would also affect Plunker version. What I think is happening that a file you've got on the local drive got corrupted somehow.

You can surely send a pull request changing quotes to their respective \u equivalents but I really do think that the issue boils down to the changes in your local file.

@luanshixia
Copy link
Contributor Author

@pkozlowski-opensource But file is corrupted cannot explain why the messed-up code only seen in my Chrome but not my other text editors.

What I know is I have experience similar situations in TFS, also related to the wide char of quote literals. Every time a check-in file contains these chars, the code will be messed up. All my colleagues confront this. We must replace the wide quote to plain quote to resolve the issue.

Maybe it is an issue of Chrome or Windows, but it can be avoided. Since the wide quote is added in 1.3.x, I think just escaping is OK.

@Narretz
Copy link
Contributor

Narretz commented Sep 19, 2015

Looks like this landed as 39ff333

@Narretz Narretz closed this as completed Sep 19, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants