-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Incorrect Regexp fix for Style/RedundantRegexpArgument
with extraneous escaped double-quote
#13483
Comments
Hmmm... after a bit more poking around I realized that The issue is that it's run after
And run:
it corrects that line to be:
(removing the redundant And then if I run:
It properly corrects it to now be:
So I don't know if the best way to deal with this is to add a fix to If there is an ordering to the cops, maybe |
Great investigative work! Issues where autocorrect from one cop steps on the toes of another crop up every once in a while. The solution will be to declare them incompatible so that they happen in two passes. You can check out #13369 as a template if you want to make a PR yourself. |
…RegexpArgument` Fixes rubocop#13483. This PR fixes an incorrect autocorrect for `Style/RedundantRegexpArgument` when using escaped double quote character.
|
We discovered a strange corner-case where a gsub that includes an unnecessarily-escaped double-quote gets autocorrected in a way that affects the gsub. I believe this is an anomaly because Ruby handles
/"/
and/\"/
the same way... that is: the extra back-slash is extraneous but the Rubocop rule doesn't handle it as such.Ruby apparently treats these the same:
Expected behavior
When passed through
Style/RedundantRegexpArgument
and autocorrected the following line:"an escaped \"double-quote\" value".gsub(/\"/, """)
should turn into:
"an escaped \"double-quote\" value".gsub('"', """)
both lines run as normal Ruby output the gsub the same way:
Actual behavior
"an escaped \"double-quote\" value".gsub(/\"/, """)
becomes instead:
"an escaped \"double-quote\" value".gsub('\"', """)
(the
\
is left in there). And that doesn't process the input string the same way:Steps to reproduce the problem
I just created a simple
test.rb
file with this in it:I verified it ran fine and the output was as expected:
I then ran the rubocop with autocorrect:
which changed it to:
But now that runs as:
which means the gsub isn't working.
RuboCop version
I originally tested this on
1.64.1
as that is what we are using in our Ruby2.7.6
main environment:But I also tested it on the latest version in our Ruby
3.3.3
environment and can confirm it fails there as well:The text was updated successfully, but these errors were encountered: