Skip to content

Commit 263257a

Browse files
committed
Make || alternations respect :ratchet mode
:ratchet mode already stopped the regex engine from backtracking into quantifiers and `|` (LTM) alternations. Now it also stops it from backtracking into `||` (sequential) alternations. (Fixes RT #130117)
1 parent e5e5a3f commit 263257a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/vm/jvm/QAST/Compiler.nqp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5264,6 +5264,12 @@ class QAST::CompilerJAST {
52645264
my $endlabel := JAST::Label.new( :name($prefix ~ 'end') );
52655265
my $altlabel := JAST::Label.new( :name($prefix ~ $altcount) );
52665266
my $ajast := self.regex_jast(nqp::shift($iter));
5267+
5268+
my $mark_endlabel := &*REGISTER_MARK($endlabel);
5269+
self.regex_mark($il, $mark_endlabel,
5270+
$IVAL_MINUSONE,
5271+
$IVAL_ZERO);
5272+
52675273
while $iter {
52685274
$il.append($altlabel);
52695275
$altcount++;
@@ -5273,6 +5279,7 @@ class QAST::CompilerJAST {
52735279
JAST::Instruction.new( :op('lload'), %*REG<pos> ),
52745280
$IVAL_ZERO);
52755281
$il.append($ajast);
5282+
self.regex_commit($il, $mark_endlabel) if $node.backtrack eq 'r';
52765283
$il.append(JAST::Instruction.new( :op('goto'), $endlabel ));
52775284
$ajast := self.regex_jast(nqp::shift($iter));
52785285
}

src/vm/moar/QAST/QASTRegexCompilerMAST.nqp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,15 @@ class QAST::MASTRegexCompiler {
316316
my $altlabel_index := self.rxjump();
317317
my $altlabel := @!rxjumps[$altlabel_index];
318318
my @amast := self.regex_mast(nqp::shift($iter));
319+
self.regex_mark(@ins, $endlabel_index, %!reg<negone>, %!reg<zero>);
319320
while $iter {
320321
nqp::push(@ins, $altlabel);
321322
$altcount++;
322323
$altlabel_index := self.rxjump();
323324
$altlabel := @!rxjumps[$altlabel_index];
324325
self.regex_mark(@ins, $altlabel_index, %!reg<pos>, %!reg<zero>);
325326
merge_ins(@ins, @amast);
327+
self.regex_commit(@ins, $endlabel_index) if $node.backtrack eq 'r';
326328
nqp::push(@ins, op('goto', $endlabel));
327329
@amast := self.regex_mast(nqp::shift($iter));
328330
}

0 commit comments

Comments
 (0)