Skip to content
forked from v8/v8

Commit

Permalink
[regexp] Handle empty ranges in unicode sets
Browse files Browse the repository at this point in the history
If a unicode set operation contains only an empty range, we generated a
set expression without operands. However the expression should match
nothing, so add the special operand not matching anything instead.

Bug: chromium:1437346
Change-Id: I8dd58884aaf6915277c80effbda43ea715049146
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4474547
Commit-Queue: Patrick Thier <pthier@chromium.org>
Reviewed-by: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#87257}
  • Loading branch information
pthier authored and V8 LUCI CQ committed Apr 25, 2023
1 parent d5c2439 commit 91fce33
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/regexp/regexp-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2774,6 +2774,14 @@ RegExpTree* RegExpParserImpl<CharT>::ParseClassUnion(
return ReportError(RegExpError::kNegatedCharacterClassWithStrings);
}

if (operands->is_empty()) {
// Return empty expression if no operands were added (e.g. [\P{Any}]
// produces an empty range).
DCHECK(ranges->is_empty());
DCHECK(strings->empty());
return RegExpClassSetExpression::Empty(zone(), is_negated);
}

return zone()->template New<RegExpClassSetExpression>(
RegExpClassSetExpression::OperationType::kUnion, is_negated,
may_contain_strings, operands);
Expand Down
5 changes: 5 additions & 0 deletions test/mjsunit/regress/regress-crbug-1437346.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright 2023 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

assertFalse(/[\P{Any}]/v.test());

0 comments on commit 91fce33

Please sign in to comment.