Skip to content

Commit 0a4693a

Browse files
committed
[RegExp] Validate range of quantification
1 parent aa64008 commit 0a4693a

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/src/regexp/node.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,16 @@ class IntersectionNode extends Node {
151151
}
152152

153153
class QuantificationNode extends Node {
154-
QuantificationNode(this.child, this.min, [this.max]);
154+
QuantificationNode(this.child, this.min, [this.max]) {
155+
RangeError.checkNotNegative(min, 'min', 'Minimum must be non-negative');
156+
if (max != null && max! < min) {
157+
throw RangeError.value(
158+
max!,
159+
'max',
160+
'Maximum must be greater than or equal to minimum ($min)',
161+
);
162+
}
163+
}
155164

156165
final Node child;
157166
final int min;

test/regexp_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ void main() {
105105
QuantificationNode(la, 34, 567),
106106
);
107107
});
108+
test('repeat invalid', () {
109+
expect(() => Node.fromString('a{3,2}'), throwsRangeError);
110+
});
108111
test('concat and or', () {
109112
expectedEqual(
110113
Node.fromString(r'ab|cd'),

0 commit comments

Comments
 (0)