-
-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
RuboCop::Cop::Performance::Casecmp broke my code #101
Comments
koic
added a commit
to koic/rubocop-performance
that referenced
this issue
May 4, 2020
Fixes rubocop#101. This PR marks unsafe for `Performance/Casecmp` cop. `String#casecmp` and `String#casecmp?` behave differently when using Non-ASCII characters. ```console 'äöü'.casecmp('ÄÖÜ').zero? #=> false 'äöü'.casecmp?('ÄÖÜ') #=> true ``` I thought about using a String literal encoding to prevent false positives. But, it is difficult to static analyze the encoding of strings passed from outside. As a result, I decided to mark it as unsafe.
koic
added a commit
to koic/rubocop-performance
that referenced
this issue
May 4, 2020
Fixes rubocop#101. This PR marks unsafe for `Performance/Casecmp` cop. `String#casecmp` and `String#casecmp?` behave differently when using Non-ASCII characters. ```console 'äöü'.casecmp('ÄÖÜ').zero? #=> false 'äöü'.casecmp?('ÄÖÜ') #=> true ``` I thought about using a String literal encoding to prevent false positives. But, it is difficult to static analyze the encoding of strings passed from outside. As a result, this PR marks unsafe for `Performance/Casecmp` cop.
koic
added a commit
to koic/rubocop-performance
that referenced
this issue
May 4, 2020
Fixes rubocop#101. `String#casecmp` and `String#casecmp?` behave differently when using Non-ASCII characters. ```console 'äöü'.casecmp('ÄÖÜ').zero? #=> false 'äöü'.casecmp?('ÄÖÜ') #=> true ``` I thought about using a String literal encoding to prevent false positives. But, it is difficult to static analyze the encoding of strings passed from outside. As a result, this PR marks unsafe for `Performance/Casecmp` cop.
8 tasks
Thanks for the feedback. I opened a PR #104. |
koic
added a commit
that referenced
this issue
May 7, 2020
[Fix #101] Mark unsafe for `Performance/Casecmp` cop
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
a.casecmp(b).zero?
is not an universal replacement fora.downcase == b.downcase
casecmp
only supports characters A-Za-z.downcase
supports special characters as well"ÄÖÜ".downcase == "äöü"
Expected behavior
Rubocop does not change the semantics of my program.
Actual behavior
Rubocop breaks my code.
Steps to reproduce the problem
foo.rb
rubocop -a foo.rb
foo.rb
RuboCop version
The text was updated successfully, but these errors were encountered: