Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

The #URL_REGEX class property was defined with the g flag, making it stateful. Reusing it across multiple .test() and .exec() calls caused lastIndex to persist, leading to unpredictable matching behavior.

Changes:

  • Removed g flag from #URL_REGEX class property definition
  • Create fresh global regex instance when needed for #addMatchedRanges()
  • .test() now safely uses non-global regex
// Before: stateful, unpredictable
#URL_REGEX = /[a-zA-Z0-9+.-]*:\/\/[^\s]+/g;
this.#addMatchedRanges(content, this.#URL_REGEX, ranges);      // mutates lastIndex
if (this.#URL_REGEX.test(beforePath)) { ... }                   // uses stale lastIndex

// After: stateless, predictable
#URL_REGEX = /[a-zA-Z0-9+.-]*:\/\/[^\s]+/;
this.#addMatchedRanges(content, new RegExp(this.#URL_REGEX, 'g'), ranges);
if (this.#URL_REGEX.test(beforePath)) { ... }                   // fresh state

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI mentioned this pull request Nov 5, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 5, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Note

Free review on us!

CodeRabbit is offering free reviews until Thu Nov 06 2025 to showcase some of the refinements we've made.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 2 commits November 5, 2025 11:44
… bug

Co-authored-by: pan93412 <28441561+pan93412@users.noreply.github.com>
Co-authored-by: pan93412 <28441561+pan93412@users.noreply.github.com>
Copilot AI changed the title [WIP] Address feedback on URL and case rules fix Fix stateful regex bug in URL pattern matching Nov 5, 2025
Copilot AI requested a review from pan93412 November 5, 2025 11:47
@pan93412 pan93412 marked this pull request as ready for review November 5, 2025 11:50
@pan93412 pan93412 merged commit 8f60e7c into alternatives-for-caserules Nov 5, 2025
5 of 7 checks passed
@pan93412 pan93412 deleted the copilot/sub-pr-29 branch November 5, 2025 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants