Skip to content

Conversation

@alexanderadam
Copy link
Contributor

@alexanderadam alexanderadam commented Oct 21, 2025

fixes #52

PS: I'm looking for a new adventure in case anybody is looking to hire or work with a Ruby/Rails/Crystal dev

@alexanderadam alexanderadam force-pushed the fix/dont_crash_on_utf16_method_autocompletion branch from 1c50bc8 to 2759a0a Compare October 22, 2025 22:22
@alexanderadam alexanderadam force-pushed the fix/dont_crash_on_utf16_method_autocompletion branch 2 times, most recently from 0550394 to 795b975 Compare October 26, 2025 22:58
@alexanderadam alexanderadam requested a review from tompng October 26, 2025 23:04
@alexanderadam
Copy link
Contributor Author

Thank you so much for your valuable advice @tompng 🙏

@alexanderadam alexanderadam force-pushed the fix/dont_crash_on_utf16_method_autocompletion branch 2 times, most recently from 6ed23be to a5d05eb Compare October 27, 2025 09:40
@alexanderadam
Copy link
Contributor Author

It seems that I can't re-run the build?
Or at least I can't find how.
TruffleRuby failed on the CI while bundling and I created an issue for that on the TruffleRuby repo.

@eregon
Copy link
Member

eregon commented Oct 27, 2025

I schedule a rerun of that job, it's a known issue and I'm working on a fix for it.

@alexanderadam alexanderadam force-pushed the fix/dont_crash_on_utf16_method_autocompletion branch from a5d05eb to b648d18 Compare October 27, 2025 11:22
@st0012 st0012 added the bug Something isn't working label Oct 27, 2025
@st0012
Copy link
Member

st0012 commented Oct 27, 2025

Looking at the code, looks like the change is addressing the issue with utf16? Is that's the case, can you update both commit message and the PR title?

@alexanderadam alexanderadam changed the title fix: don't crash on utf18 autocompletion fix: don't crash on utf16 autocompletion Oct 27, 2025
@alexanderadam alexanderadam force-pushed the fix/dont_crash_on_utf16_method_autocompletion branch from b648d18 to 84663b1 Compare October 27, 2025 12:00
@alexanderadam alexanderadam changed the title fix: don't crash on utf16 autocompletion Fix UTF-16 autocompletion Oct 27, 2025
@alexanderadam
Copy link
Contributor Author

Looking at the code, looks like the change is addressing the issue with utf16? Is that's the case, can you update both commit message and the PR title?

It is indeed 😆
I changed both now to be correct.

Comment on lines 460 to 461
# Remove BOM (U+FEFF) which may be preserved when converting from UTF-16
converted.delete("\uFEFF")
Copy link
Member

@tompng tompng Oct 27, 2025

Choose a reason for hiding this comment

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

I think we don't need this. The original issue is about utf-16, but another realistic case is other ascii-compatible encoding method defined by code with magic comments.

#encoding: sjis
def a【codepoint=825C letter here】; end

So we don't need to consider UTF-16 specific case.
And It looks like BOM is not preserved.

'😄'.encode(Encoding::UTF_16)
# => "\xFE\xFF\xD8\x3D\xDE\x04" (has BOM)
'😄'.encode(Encoding::UTF_16).encode(Encoding::UTF_8).chars
# => ["😄"] (BOM is removed)

Other part of this pull request looks good 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is true for all tested Ruby implementations except TruffleRuby.

However, TruffleRuby adds the BOM in the beginning of the string after a conversion.

Benoit would rather see that Ruby would generally prevent such method definitions.

Copy link
Member

Choose a reason for hiding this comment

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

I see, but I don't think this should be in lib code.
Can you remove this and omit truffleruby in the added test, just like test_regexp_completor_handles_encoding_errors_gracefully does?

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 see. That makes sense. 🙂

Thank you, I changed it.

Copy link
Member

@eregon eregon Oct 28, 2025

Choose a reason for hiding this comment

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

It would be better to use Encoding::UTF_16LE/BE for testing, Encoding::UTF_16 is basically deprecated and a dummy encoding.
Even better would be to use something more realistic than UTF-16, since that's not even valid source encoding: #52 (comment)
So I think testing with SJIS as in @tompng's example is much more realistic and useful, using UTF-16 is basically a user mistake in the first place.

Copy link
Member

Choose a reason for hiding this comment

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

Adding a realistic test case looks good. I'd like to check for some existing test that use UTF16LE, encoding-invalid method and add/change in a followup pull request.

@alexanderadam alexanderadam force-pushed the fix/dont_crash_on_utf16_method_autocompletion branch from 84663b1 to fed1886 Compare October 27, 2025 21:45
Copy link
Member

@tompng tompng left a comment

Choose a reason for hiding this comment

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

Looks good 👍
Thank you

@tompng tompng merged commit 18d152b into ruby:master Oct 28, 2025
33 checks passed
@alexanderadam alexanderadam deleted the fix/dont_crash_on_utf16_method_autocompletion branch October 28, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working hacktoberfest-accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A method what is named with an encoding what is incompatible with Encoding.default_external causes crash

4 participants