From feb0f425731cfdea541e8ef1d7bbb55d332db460 Mon Sep 17 00:00:00 2001 From: yosuke ota Date: Fri, 20 Oct 2023 21:36:12 +0900 Subject: [PATCH 1/4] fix: crash for v flag in `regexp/optimal-quantifier-concatenation` --- lib/rules/optimal-quantifier-concatenation.ts | 10 +++++++++- tests/lib/rules/optimal-quantifier-concatenation.ts | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/rules/optimal-quantifier-concatenation.ts b/lib/rules/optimal-quantifier-concatenation.ts index a1b8b6dfd..813158c9b 100644 --- a/lib/rules/optimal-quantifier-concatenation.ts +++ b/lib/rules/optimal-quantifier-concatenation.ts @@ -55,6 +55,10 @@ const EMPTY_UNICODE: SingleConsumedChar = { char: Chars.empty({ unicode: true }), complete: false, } +const EMPTY_UNICODE_SETS: SingleConsumedChar = { + char: Chars.empty({ unicodeSets: true }), + complete: false, +} /** * If the given element is guaranteed to only consume a single character set, @@ -64,7 +68,11 @@ function getSingleConsumedChar( element: Element | Alternative, flags: ReadonlyFlags, ): SingleConsumedChar { - const empty = flags.unicode ? EMPTY_UNICODE : EMPTY_UTF16 + const empty = flags.unicodeSets + ? EMPTY_UNICODE_SETS + : flags.unicode + ? EMPTY_UNICODE + : EMPTY_UTF16 switch (element.type) { case "Alternative": diff --git a/tests/lib/rules/optimal-quantifier-concatenation.ts b/tests/lib/rules/optimal-quantifier-concatenation.ts index aa75171b2..20580cecc 100644 --- a/tests/lib/rules/optimal-quantifier-concatenation.ts +++ b/tests/lib/rules/optimal-quantifier-concatenation.ts @@ -25,6 +25,7 @@ tester.run("optimal-quantifier-concatenation", rule as any, { }, String.raw`/^(?:\[\[\[?.+?\]?\]\]|<<.+?>>)$/`, String.raw`/a\s*?(?=\r?\n|\r)/`, + String.raw`/(?:a|b)?c/v`, ], invalid: [ { From f92a291b14b16b9d9f0b8088158a469e4a550292 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 20 Oct 2023 21:37:23 +0900 Subject: [PATCH 2/4] Create chilly-pumpkins-raise.md --- .changeset/chilly-pumpkins-raise.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilly-pumpkins-raise.md diff --git a/.changeset/chilly-pumpkins-raise.md b/.changeset/chilly-pumpkins-raise.md new file mode 100644 index 000000000..79732572c --- /dev/null +++ b/.changeset/chilly-pumpkins-raise.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-regexp": patch +--- + +Fixed crash for v flag in `regexp/optimal-quantifier-concatenation` From e33fcac6f5ed26c79ea679c5f5244b02faaa61db Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Sat, 21 Oct 2023 08:37:12 +0900 Subject: [PATCH 3/4] Update lib/rules/optimal-quantifier-concatenation.ts Co-authored-by: Michael Schmidt --- lib/rules/optimal-quantifier-concatenation.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/rules/optimal-quantifier-concatenation.ts b/lib/rules/optimal-quantifier-concatenation.ts index 813158c9b..0373d12cf 100644 --- a/lib/rules/optimal-quantifier-concatenation.ts +++ b/lib/rules/optimal-quantifier-concatenation.ts @@ -68,9 +68,7 @@ function getSingleConsumedChar( element: Element | Alternative, flags: ReadonlyFlags, ): SingleConsumedChar { - const empty = flags.unicodeSets - ? EMPTY_UNICODE_SETS - : flags.unicode + const empty = flags.unicode || flags.unicodeSets ? EMPTY_UNICODE : EMPTY_UTF16 From 1c5c3110cbe084fef8df19e7bd316d210ba0bb43 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Fri, 20 Oct 2023 23:40:35 +0000 Subject: [PATCH 4/4] fix --- lib/rules/optimal-quantifier-concatenation.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/rules/optimal-quantifier-concatenation.ts b/lib/rules/optimal-quantifier-concatenation.ts index 0373d12cf..967907652 100644 --- a/lib/rules/optimal-quantifier-concatenation.ts +++ b/lib/rules/optimal-quantifier-concatenation.ts @@ -55,10 +55,6 @@ const EMPTY_UNICODE: SingleConsumedChar = { char: Chars.empty({ unicode: true }), complete: false, } -const EMPTY_UNICODE_SETS: SingleConsumedChar = { - char: Chars.empty({ unicodeSets: true }), - complete: false, -} /** * If the given element is guaranteed to only consume a single character set, @@ -68,9 +64,8 @@ function getSingleConsumedChar( element: Element | Alternative, flags: ReadonlyFlags, ): SingleConsumedChar { - const empty = flags.unicode || flags.unicodeSets - ? EMPTY_UNICODE - : EMPTY_UTF16 + const empty = + flags.unicode || flags.unicodeSets ? EMPTY_UNICODE : EMPTY_UTF16 switch (element.type) { case "Alternative":