Umayr
Umayr

Reputation: 933

Phantom JS + Angular JS - Parse Error

I'm getting SyntaxError: Parse error while executing unit tests with Karma on PhantomJS.

PhantomJS 1.9.7 (Windows 7) ERROR
    SyntaxError: Parse error
    at d:/Path/To/File/index.html.js.js.js.js:11
PhantomJS 1.9.7 (Windows 7): Executed 0 of 0 ERROR (0.512 secs / 0 secs)

At this line in mentioned html file, I have a conditional angular statement:

{{ condition && "String with an escaped \' apostrophe" || "Another string without any escaped characters."}}

When I remove this escaped apostrophe, it works fine. I'm using Angular 1.0.8, Karma 1.4.14 and PhantomJS 1.9.7. I want to know if there is a workaround without updating any packages. And I very much like to keep this apostrophe. Thank you.

Edit

On chrome I'm getting this error:

Chrome 37.0.2062 (Windows 7) ERROR
    Uncaught SyntaxError: Unexpected identifier
    at d:/Path/To/File/index.html.js:11
Chrome 37.0.2062 (Windows 7): Executed 0 of 0 ERROR (2.576 secs / 0 secs)

Upvotes: 1

Views: 1187

Answers (1)

user1421750
user1421750

Reputation: 1230

In JavaScript you don't need to escape single quotes in a double quoted string. "'" produces a string with an apostrophe. "\'" is invalid, because \' is an invalid escape sequence. If you want to produce a string with a backslash before an apostrophe you'll need to do "\\'", escaping the backslash.

Upvotes: 2

Related Questions