Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #11150] Catch redundant hyphen escape within character class #11152

Merged

Conversation

si-lens
Copy link
Contributor

@si-lens si-lens commented Nov 4, 2022

Fix: #11150
It should catch redundant regexp escape when the hyphen is being escaped and at the same time is the first or the last character within the character class.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@si-lens si-lens marked this pull request as ready for review November 4, 2022 15:52
else
ALLOWED_OUTSIDE_CHAR_CLASS_METACHAR_ESCAPES.include?(char)
end
end

def char_class_begins_or_ends_with_hypen?(node, index)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not very clear what this function does, so perhaps it'd better to document it a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know how to check in a better, more descriptive way :(
I hope that with documentation it's better but I am open to any suggestions 🙏🏻

@si-lens si-lens force-pushed the improve_redundant_regex_escape_catching branch from 5771575 to cc23ff0 Compare November 12, 2022 17:21
Catch redundant regexp escape when the escaped hyphen is the first or the last character within the character class.
@si-lens si-lens force-pushed the improve_redundant_regex_escape_catching branch from cc23ff0 to c266b39 Compare November 12, 2022 17:22
@si-lens si-lens requested a review from bbatsov November 12, 2022 17:35
Copy link
Collaborator

@bbatsov bbatsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants