[ruby-dev:50035] [Ruby trunk Bug#13352] RegExp infinite looping

From: jumnichi.kose@...
Date: 2017-03-23 00:49:59 UTC
List: ruby-dev #50035
Issue #13352 has been updated by jumnichi_kose (=E5=B0=8F=E7=80=AC =E6=B7=
=B3=E4=B8=80).


Thank' to @naruse

> https://regex101.com/

Your's workaround is fine.

It OK that "Somewhere in my regular expression was bad".

But,I do not understand what was wrong with my RexExp.


A similar regular expression does not fall into an infinite loop.
~~~ ruby
r =3D /\[((?:[^none of\]]*|other)*)\]/
a=3D"[data]"
a[0...(-2)].scan r # =3D> []
a.scan r # =3D>  [["data"]]

~~~

The other workaround was to not use "none of".
~~~ ruby
r =3D /(?=3D\W)\W?(?:(?:(?:\/\*<)?[\'\"]?([\w_\$]+)[\'\"]?(?:>\*\/\s+this)?=
|(this))\.(\$scope|json)|([\'\"](?:\$scope|json)[\'\"]))((\.)(inputObjects)=
|(\.)(spreadSheets)(?:\.[\'\"]?([\w_\$]+)[\'\"]?|\[[\'\"]?((?:[\w\s(\.)+\-\=
/_|!]*|\[[\w\s(\.)+\-\/_|!]\])*)[\'\"]?\])(\.)(model))\s*(?:\.[\'\"]?([\w_\=
$]+)[\'\"]?|\[[\'\"]?((?:[\w\s(\.)+\-\/_|!]+|\[[\w\s(\.)+\-\/_|!]*\]|\/\*[\=
w\s(\.)+\-\/_|!]+\*\/)+)[\'\"]?\])/

txt =3D ".model |,| 'anController'.$scope.inputObjects['fieldName .../* !! =
comment ...*/]"

txt.scan r # =3D>  [["anController", nil, "$scope", nil, ".inputObjects", "=
.", "inputObjects", nil, nil, nil, nil, nil, nil, nil, "fieldName .../* !! =
comment ...*/"]]

txt[0..(-2)].scan # =3D> []

~~~

I am glad when the site that is explained where is wrong is introduced.


----------------------------------------
Bug #13352: RegExp infinite looping
https://bugs.ruby-lang.org/issues/13352#change-63738

* Author: jumnichi_kose (=E5=B0=8F=E7=80=AC =E6=B7=B3=E4=B8=80)
* Status: Rejected
* Priority: Normal
* Assignee:=20
* Target version:=20
* ruby -v: 2.3.3p222 (2016-11-21 revision 56859) [x64-mingw32],  ruby 2.2.4=
p230 (2015-12-16 revision 53155) [i386-mingw32]
* Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN
----------------------------------------
ruby entered an infinite loop with the following three steps.

~~~ ruby
r =3D /(?=3D\W)\W?(?:(?:(?:\/\*<)?[\'\"]?([\w_\$]+)[\'\"]?(?:>\*\/\s+this)?=
|(this))\.(\$scope|json)|([\'\"](?:\$scope|json)[\'\"]))((\.)(inputObjects)=
|(\.)(spreadSheets)(?:\.[\'\"]?([^\.\'\"\|\s,]+)[\'\"]?|\[[\'\"]?((?:[^\'\"=
\]\[]*|\[[^\]]*\])*)[\'\"]?\])(\.)(model))\s*(?:\.[\'\"]?([^\.\'\"\|\s,]+)[=
\'\"]?|\[[\'\"]?((?:[^\'\"\]\[]*|\[[^\]]*\])*)[\'\"]?\])/
txt =3D ".model |,| 'anController'.$scope.inputObjects['fieldName .../* !! =
comment ...*/"
txt.scan r
~~~

Node.js also falls into an infinite loop.
~~~ javascript
var r =3D /(?=3D\W)\W?(?:(?:(?:\/\*<)?[\'\"]?([\w_\$]+)[\'\"]?(?:>\*\/\s+th=
is)?|(this))\.(\$scope|json)|([\'\"](?:\$scope|json)[\'\"]))((\.)(inputObje=
cts)|(\.)(spreadSheets)(?:\.[\'\"]?([^\.\'\"\|\s,]+)[\'\"]?|\[[\'\"]?((?:[^=
\'\"\]\[]*|\[[^\]]*\])*)[\'\"]?\])(\.)(model))\s*(?:\.[\'\"]?([^\.\'\"\|\s,=
]+)[\'\"]?|\[[\'\"]?((?:[^\'\"\]\[]*|\[[^\]]*\])*)[\'\"]?\])/
var txt =3D ".model |,| 'anController'.$scope.inputObjects['fieldName .../*=
 !! comment ...*/"

var s =3Dr.exec (txt)

console.log(s)


~~~





--=20
https://bugs.ruby-lang.org/

In This Thread

Prev Next