You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
regex v2.1.0 introduced src/backcompat.js, which extended support for most usage backward to environments without native flag v. This file is a postprocessor that is conditionally applied when flag v is not supported natively, and it does several things:
Transpiles flag v's escaping rules to u's (by un-escaping some characters).
Throws for character class syntax that is invalid with v but valid with u (unescaped (){}/|, reserved double punctuators, and leading/trailing -, since all of these would throw in environments with v).
Throws for features that require native flag v (character class set operators -- and &&, and a more descriptive error for nested character classes which are already invalid with u).
Throws when using doubly-negated [^\P{…}] if the regex uses flag i, to prevent an unintuitive (likely) behavior difference (likely, since many but not all Unicode properties include letters with case).
Regarding # 4, this is fine, but it's incomplete. At the time, I was referencing this and this, which only show examples with doubly-negated [^\P{…}]. However, as @rauschma points out here, this v/u incompatibility applies equally with \p (lowercase) in /[^\p{…}]/iu.
Updating this in src/backcompat.js to also cover \p would be easy, but would also be a (rarely applicable) breaking change. IMO it wouldn't be a problem to start throwing without a new major version if the behavior was always incompatible (since anyone with such patterns in their code would already have a bug in environments without v), but since not all uses of /[^\p{…}]/iu suffer from this issue, I will hold off on updating it until there are additional breaking changes to include in a v4.0.
The text was updated successfully, but these errors were encountered:
slevithan
changed the title
Breaking: Throw for ` regex('i')[^\p{…}] in environments without native flag v`
Breaking: Throw for [^\p{…}] with flag i in environments without native flag vJul 29, 2024
Rather than throwing for [^\p{…}] with flag i (when v is not supported natively), I resolved this by:
Not throwing for uppercase [^\P{…}] with flag i, either (since it's not actually always problematic).
Introducing new option unicodeSetsPlugin, which allows overriding the built-it plugin for backcompat with a more robust transpiler (e.g. based on regexpu-core), if needed.
regex v2.1.0 introduced
src/backcompat.js
, which extended support for most usage backward to environments without native flagv
. This file is a postprocessor that is conditionally applied when flagv
is not supported natively, and it does several things:v
's escaping rules tou
's (by un-escaping some characters).v
but valid withu
(unescaped(){}/|
, reserved double punctuators, and leading/trailing-
, since all of these would throw in environments withv
).v
(character class set operators--
and&&
, and a more descriptive error for nested character classes which are already invalid withu
).[^\P{…}]
if the regex uses flagi
, to prevent an unintuitive (likely) behavior difference (likely, since many but not all Unicode properties include letters with case).Regarding # 4, this is fine, but it's incomplete. At the time, I was referencing this and this, which only show examples with doubly-negated
[^\P{…}]
. However, as @rauschma points out here, thisv
/u
incompatibility applies equally with\p
(lowercase) in/[^\p{…}]/iu
.Updating this in
src/backcompat.js
to also cover\p
would be easy, but would also be a (rarely applicable) breaking change. IMO it wouldn't be a problem to start throwing without a new major version if the behavior was always incompatible (since anyone with such patterns in their code would already have a bug in environments withoutv
), but since not all uses of/[^\p{…}]/iu
suffer from this issue, I will hold off on updating it until there are additional breaking changes to include in a v4.0.The text was updated successfully, but these errors were encountered: