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

String#casecmp? fails between ascii and utf-8 #2826

Closed
notEthan opened this issue Jan 11, 2023 · 6 comments
Closed

String#casecmp? fails between ascii and utf-8 #2826

notEthan opened this issue Jan 11, 2023 · 6 comments

Comments

@notEthan
Copy link

Comparing an ASCII-8BIT string with UTF-8, for both of which #ascii_only? is true, using String#casecmp? returns nil rather than a boolean e.g.

''.b.casecmp?('')

It returns boolean on MRI, and the implementation to return boolean is present in truffleruby but not reached:

https://github.com/oracle/truffleruby/blob/vm-22.3.0/src/main/ruby/truffleruby/core/string.rb#L1204-L1213
The check if ascii_only? && other.ascii_only? is not reached after Primitive.encoding_compatible?(encoding, other.encoding) returns nil.

@eregon
Copy link
Member

eregon commented Jan 11, 2023

Thank you for the report.
We should use Primitive.encoding_ensure_compatible_str self, other there I suspect.

@eregon
Copy link
Member

eregon commented Jan 11, 2023

@notEthan Would you be interested to submit a PR for this, or you prefer the team fixes this? (either is fine)
I'm asking because this seems like it could be an easy contribution.

@notEthan
Copy link
Author

I had a look but getting a truffleruby development/build/test environment rolling looks to be more involved than I have time to put into this at the moment.

@eregon
Copy link
Member

eregon commented Jan 12, 2023

No worry, the team will fix it then.
Building from source is explained in https://github.com/oracle/truffleruby/blob/master/doc/contributor/workflow.md, it's mostly automated except setting up jt.

@eregon eregon self-assigned this Jan 12, 2023
@eregon eregon added this to the 23.0.0 Release milestone Jan 12, 2023
graalvmbot pushed a commit that referenced this issue Jan 13, 2023
@notEthan
Copy link
Author

Nice, thanks for fixing.
I do want to note that this applies to nonempty strings too, I just used empty strings in the example for conciseness. The code changes look like they apply to all strings, though the tests only use empty ones. (And, looking at the code changes, kinda glad I didn't try to take this on as my first easy contribution)

sophie-kaleba pushed a commit to sophie-kaleba/truffleruby that referenced this issue Jan 16, 2023
@eregon
Copy link
Member

eregon commented Jan 16, 2023

Ah yes of course. The change is to use strings for encoding negotiations (which considers code range and empty) vs only encodings of those strings.
The fix is actually just: 7a96f2c, 7dd4301 is the merge commit and include an unrelated cleanup.

sophie-kaleba pushed a commit to sophie-kaleba/truffleruby that referenced this issue Jan 17, 2023
nirvdrum pushed a commit to Shopify/truffleruby that referenced this issue Jan 30, 2023
sophie-kaleba pushed a commit to sophie-kaleba/truffleruby that referenced this issue Feb 16, 2023
john-heinnickel pushed a commit to thermofisher-jch/truffleruby that referenced this issue Aug 16, 2023
seven1m pushed a commit to seven1m/ruby_spec that referenced this issue Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants