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

createRegExpRestore explodes with an unmatched parenthesis #231

Closed
azimux opened this issue Sep 24, 2016 · 17 comments
Closed

createRegExpRestore explodes with an unmatched parenthesis #231

azimux opened this issue Sep 24, 2016 · 17 comments

Comments

@azimux
Copy link

azimux commented Sep 24, 2016

Hey hey!

We just noticed this problem after upgrading Intl. We see this failure sometimes in poltergeist and also seemed to be causing problems with our site loading in Safari:

Unhandled promise rejection SyntaxError: Invalid regular expression: unmatched parentheses

Printing out the evolution of the regex string it's trying to construct, it undergoes this path through the createRegExpRestore method before exploding when the end result [\s\S]{26}(((((((())))))))[\s\S]{38}) has an unmatched ) at the end.:

lastMatch:
function defineProperty() {
    [native code]
}
lm:
function defineProperty\(\) \{
    \[native code\]
\}
exprStr:
function defineProperty\(\) \{
    \[native code\]
\}
exprStr:
[\s\S]{52}
lastMatch:
function defineProperty\(\) \{
    \[native code\]
\}
lm:
function defineProperty\\\(\\\) \\\{
    \\\[native code\\\]
\\\}
has:
}
m:
}
lm:
function defineProperty\\\(\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
function defineProperty\\\(\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
\\\) \\\{
    \\\[native code\\\]
\\(\})
m:

lm:
()\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
()\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
)\\\) \\\{
    \\\[native code\\\]
\\(\})
m:

lm:
())\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
())\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
))\\\) \\\{
    \\\[native code\\\]
\\(\})
m:

lm:
()))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
()))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
)))\\\) \\\{
    \\\[native code\\\]
\\(\})
m:

lm:
())))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
())))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
))))\\\) \\\{
    \\\[native code\\\]
\\(\})
m:

lm:
()))))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
()))))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
)))))\\\) \\\{
    \\\[native code\\\]
\\(\})
m:

lm:
())))))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
())))))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
))))))\\\) \\\{
    \\\[native code\\\]
\\(\})
m:

lm:
()))))))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
()))))))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
)))))))\\\) \\\{
    \\\[native code\\\]
\\(\})
m:

lm:
())))))))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
())))))))\\\) \\\{
    \\\[native code\\\]
\\(\})
lm:
))))))))\\\) \\\{
    \\\[native code\\\]
\\(\})
exprStr:
function defineProperty\\\((((((((())))))))\\\) \\\{
    \\\[native code\\\]
\\(\})
exprStr:
[\s\S]{26}(((((((())))))))[\s\S]{38})
@caridy
Copy link
Collaborator

caridy commented Sep 25, 2016

@azimux, did you try to use IntlPolyfill.__disableRegExpRestore? this seems related to #197

@azimux
Copy link
Author

azimux commented Sep 26, 2016

We didn't try that but seems like that would work since it would short-circuit the failing code.

We fixed it by just rolling back to the previous version we were using, from 1.2.5^ to 1.1.0.

#197 seems to be related to the length being long, and, subjective, but the length of the lastMatch here doesn't seem very long to me. Also that issue is from June 30th and was closed on the 5th, the same day a commit went in heavily changing that method to the form we were using, making me think that it's a different issue, and, actually the Jul 5th issue might even introduce the bug mentioned in this issue: aa62d07#diff-34a6d62af0cf0b784f8444529f3130efR134

@MarkChrisLevy
Copy link

I have the same problem - after upgrading to 1.2.5 (from 1.2.4), in Safari 9.1 (11601.5.17.1).

[log] [\s\S]{15}(((((((())))))))[\s\S]{38}) (Intl.min.js, line 1)
[Error] SyntaxError: Invalid regular expression: unmatched parentheses

Just downgraded to 1.2.4 and it works again.

@caridy
Copy link
Collaborator

caridy commented Oct 18, 2016

@mtlewis can you help with this investigation?

@mtlewis
Copy link
Contributor

mtlewis commented Oct 18, 2016

@caridy sure thing, looking now.

@mtlewis
Copy link
Contributor

mtlewis commented Oct 18, 2016

Thanks for reporting this issue @azimux. To help us reproduce, would you mind logging out the value of the properties below at the start of the createRegExpRestore method please? Once I can reproduce the issue I should be able to track down the cause.

  • RegExp.input
  • RegExp.leftContext
  • RegExp.multiline
  • RegExp.$1
  • RegExp.$2
  • RegExp.$3
  • RegExp.$4
  • RegExp.$5
  • RegExp.$6
  • RegExp.$7
  • RegExp.$8
  • RegExp.$9

@azimux
Copy link
Author

azimux commented Oct 19, 2016

@mtlewis When it explodes, here's what those values are:

RegExp.input = function defineProperty\(\) \{
    \[native code\]
\}
RegExp.leftContext = 
RegExp.multiline = false
RegExp.$1 = }
RegExp.$2 = 
RegExp.$3 = 
RegExp.$4 = 
RegExp.$5 = 
RegExp.$6 = 
RegExp.$7 = 
RegExp.$8 = 
RegExp.$9 = 

Btw, I really dug The Big Short. Read it twice. Nice work, sir, nice work! :trollface:

@azimux
Copy link
Author

azimux commented Oct 19, 2016

Hmmm, probably better if I give you the JSON.stringify of the values so you can plug it in more easily:

createRegExpRestore intlRegExp.input = "function defineProperty\\(\\) \\{\n    \\[native code\\]\n\\}"
createRegExpRestore intlRegExp.leftContext = ""
createRegExpRestore intlRegExp.multiline = false
createRegExpRestore intlRegExp.$1 = "}"
createRegExpRestore intlRegExp.$2 = ""
createRegExpRestore intlRegExp.$3 = ""
createRegExpRestore intlRegExp.$4 = ""
createRegExpRestore intlRegExp.$5 = ""
createRegExpRestore intlRegExp.$6 = ""
createRegExpRestore intlRegExp.$7 = ""
createRegExpRestore intlRegExp.$8 = ""
createRegExpRestore intlRegExp.$9 = ""

@mtlewis
Copy link
Contributor

mtlewis commented Oct 20, 2016

Thanks a lot for getting back to me @azimux. Phew! This was a doozy. A couple of problems to track down with the previous implementation of createRegExpRestore. All sorted in #244 I believe.

@caridy, mind taking a look at the PR?

mtlewis added a commit to mtlewis/Intl.js that referenced this issue Oct 20, 2016
mtlewis added a commit to mtlewis/Intl.js that referenced this issue Oct 20, 2016
@mtlewis
Copy link
Contributor

mtlewis commented Oct 20, 2016

@caridy also, is the plan still to release a new major version which disables RegEx cache/restore by default?

mtlewis added a commit to mtlewis/Intl.js that referenced this issue Oct 21, 2016
mtlewis added a commit to mtlewis/Intl.js that referenced this issue Oct 21, 2016
mtlewis added a commit to mtlewis/Intl.js that referenced this issue Oct 26, 2016
…xRestore

Previously this expression contains a fragment similar to /aa*/ - have simplified this to /a+/.
@wojtekmaj
Copy link

Had the same problem, rollback to 1.2.4 helped right away.

@fetis
Copy link

fetis commented Mar 14, 2017

Got the same problem with Angular DatePipe (yes, it uses Intl internally), rollback to 1.2.4 helped as was mentioned above.

@caridy
Copy link
Collaborator

caridy commented Apr 3, 2017

Did you try to disabled the regexp cache? More details here: https://github.com/andyearnshaw/Intl.js#locale-data, read the second paragraph, and let us know.

@Blasz
Copy link

Blasz commented May 2, 2017

@caridy Disabling regexp cache fixed the issue for me.

@EwanMcP
Copy link

EwanMcP commented May 8, 2017

Also had the same issue, disabling cache worked but decided to revert to 1.2.4 for time being.

@jerone
Copy link

jerone commented May 16, 2017

Having the same issue. Rolling back to 1.2.4 solved it. This issue should clearly be reopened!

@neutraali
Copy link

Spent hours fighting with this bug. Finally got it working in 1.2.5 by using Intl.__disableRegExpRestore() - Props to @caridy.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants