Skip to content

Fix CSS selector id parsing#191

Open
ydah wants to merge 2 commits into
mainfrom
fix/css-selector-id-parsing
Open

Fix CSS selector id parsing#191
ydah wants to merge 2 commits into
mainfrom
fix/css-selector-id-parsing

Conversation

@ydah

@ydah ydah commented Jun 23, 2026

Copy link
Copy Markdown
Member

Fix CSS selector id parsing so Capybara/SpecificFinders only autocorrects supported simple id selectors.

Previously CssSelector.id removed every # in the selector and trimmed matcher suffixes with a broad regexp. That meant unsupported CSS identifier syntax such as multiple id selectors, escaped #, quoted values, or Unicode escapes could still be treated as a safe id and produce an incorrect find_by_id autocorrection.

This changes id detection to a strict anchored pattern for simple ids and the existing supported escapes, and skips the offense when parsing is unsupported.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with main (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • [-] Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

If you have created a new cop:

  • [-] Added the new cop to config/default.yml.
  • [-] The cop is configured as Enabled: pending in config/default.yml.
  • [-] The cop documents examples of good and bad code.
  • [-] The tests assert both that bad code is reported and that good code is not reported.
  • [-] Set VersionAdded: "<<next>>" in default/config.yml.

If you have modified an existing cop's configuration options:

  • [-] Set VersionChanged: "<<next>>" in config/default.yml.

@ydah ydah requested a review from a team as a code owner June 23, 2026 23:17
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.

1 participant