File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -968,17 +968,13 @@ if (isForwardRange!R && is(ElementType!R : dchar))
968968 case ' 1' : .. case ' 9' :
969969 uint nref = cast (uint ) front - ' 0' ;
970970 immutable maxBackref = sum(g.groupStack.data);
971- enforce(nref < maxBackref, " Backref to unseen group" );
972- // perl's disambiguation rule i.e.
973- // get next digit only if there is such group number
974971 popFront();
975- while (nref < maxBackref && ! empty && std.ascii.isDigit (front))
972+ while (! empty && std.ascii.isDigit (front))
976973 {
977974 nref = nref * 10 + front - ' 0' ;
978975 popFront();
979976 }
980- if (nref >= maxBackref)
981- nref /= 10 ;
977+ enforce(nref < maxBackref, " Backref to unseen group" );
982978 enforce(! g.isOpenGroup(nref), " Backref to open group" );
983979 uint localLimit = maxBackref - g.groupStack.top;
984980 if (nref >= localLimit)
Original file line number Diff line number Diff line change @@ -711,3 +711,12 @@ version (none) // TODO: revist once we have proper benchmark framework
711711 ma = ma2;
712712 assert (ma[1 ] == " " );
713713}
714+
715+ // https://github.com/dlang/phobos/issues/11035
716+ @safe unittest
717+ {
718+ assertThrown(regex(` (a)\12` ));
719+ assertThrown(regex(` (a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\123` ));
720+ // a valid multi-digit backref still works
721+ assertNotThrown(regex(` (a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)(l)\12` ));
722+ }
You can’t perform that action at this time.
0 commit comments