5

Failed to save undefined... Unterminated string... <code>/\"I want a double quoted string\"/g</code>

As shown in the image, when trying to create a regular expression in a lightning component controller, the save from the developer console fails because of an error parsing the data.

6

You'll want to log a bug with this; it appears that the quotes do need to be matched in Spring 17, and this behavior also does not appear in Winter 16. For now, you should be able to escape one quote to bring the balance back. Here's an example of a broken regex in Spring 17:

    var r = /src="([^"]+)"/g;

Here's a way to fix it:

    var r = /src="([^\"]+)"/g;

I did a simple test to make sure the results still worked:

    var r = /src="([^\"]+)"/g;
    var d = "<img src=\"www.google.com\" width=\"100\" height=\"100\" />";
    console.log(r.exec(d));

Output:

[0]: src="www.google.com"
[1]: www.google.com
index: 5

Update

Gordon Oliver has this to say about the issue:

There are no known changes to the validation that would cause this, so we will open a bug and investigate to find the root cause.

13
  • 1
    @DanielBallinger I was just about to notice that when you edited. Thanks for the edit, though, because I might have missed it for some time. – sfdcfox Jan 18 '17 at 19:52
  • 4
    I've raised this directly with the team that owns the Lightning compiler bits and asked them to comment. – Doug Chasman Jan 18 '17 at 21:47
  • 1
    @DougChasman Thanks! This seems like it'll a pretty major bug if it gets to production. – sfdcfox Jan 18 '17 at 21:54
  • 2
    There are no known changes to the validation that would cause this, so we will open a bug and investigate to find the root cause. – Gordon Oliver Jan 19 '17 at 20:22
  • 1
    @DougChasman Thank you very much, as stated this is not a blocking issue since I can work around the regex issue, but I thought it important to raise the question! – Etienne Rocheleau Jan 19 '17 at 20:37
1

This is actually a known bug, and it has a workaround, which is to use:

var r = new Regex("src=\"([^\"]+)\"/g");

instead of using the // syntax:

var r = /src="([^"]+)"/g;

I tried this on both Winter '16, and Spring '17, and both cases had the same exception for the expression syntax, and both were fixed using the new Regex syntax.

2
  • Ok thank you, I fixed it also by using new Regexp() Which seems to work or by changing the regex to a different format that does not break the salesforce validation. – Etienne Rocheleau Jan 19 '17 at 21:01
  • @Gordon Oliver I have used the above said workaround but I am getting Uncaught Action failed: c:Graph$controller$handleActive [Unable to evaluate code at: components/c/activityfeed.js] error when loading the page.This is my regex var token = /d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g; Made it like this var token = new Regex("d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|\"[^\"]*\"|'[^']*'/g"); – Furquan Khan Oct 16 '17 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.