Skip to content
forked from v8/v8

Commit

Permalink
Reland "[regexp] Handle empty ranges in unicode sets"
Browse files Browse the repository at this point in the history
This is a reland of commit 91fce33

Changes since revert:
- Skip added test in no-internalization builds.

Original change's description:
> [regexp] Handle empty ranges in unicode sets
>
> 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}

Bug: chromium:1437346
Change-Id: I60a19a6feb72a82873e3c82ca0a3d3d38bbc1ad9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4474551
Auto-Submit: Patrick Thier <pthier@chromium.org>
Reviewed-by: Jakob Linke <jgruber@chromium.org>
Commit-Queue: Jakob Linke <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/main@{#87268}
  • Loading branch information
pthier authored and V8 LUCI CQ committed Apr 25, 2023
1 parent 34a8d25 commit cb8697b
Show file tree
Hide file tree
Showing 3 changed files with 14 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
1 change: 1 addition & 0 deletions test/mjsunit/mjsunit.status
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@
'harmony/regexp-property-*': [PASS,FAIL],
'regress/regress-1262423': [PASS,FAIL],
'regress/regress-793588': [PASS,FAIL],
'regress/regress-crbug-1437346': [PASS,FAIL],

# RegExp unicode tests relies on ICU for property classes and
# case-insensitive unicode patterns.
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 cb8697b

Please sign in to comment.