Skip to content

Use rb_utf8_str_new_cstr() in Ruby C-Extension#500

Merged
marcoroth merged 1 commit intomainfrom
ruby-utf8-strings
Sep 16, 2025
Merged

Use rb_utf8_str_new_cstr() in Ruby C-Extension#500
marcoroth merged 1 commit intomainfrom
ruby-utf8-strings

Conversation

@marcoroth
Copy link
Owner

@marcoroth marcoroth commented Sep 16, 2025

This pull request updates the Ruby C-Extension to use rb_utf8_str_new_cstr() over rb_str_new_cstr() when constructing Ruby Strings from the C char[].

This ensures we always have a UTF-8 string so we don't trigger a Encoding::CompatibilityError (incompatible character encodings: BINARY (ASCII-8BIT) and UTF-8) when concatenating strings.

It looks like rb_str_new_cstr() sometimes produces an UTF-8 string and sometimes an ASCII-8BIT string based on the content.

Resolves #492
Resolves marcoroth/reactionview#4

@flavorjones
Copy link

Just confirming that this branch fixes the issue I experienced related to marcoroth/reactionview#4 ! 🙏

@marcoroth
Copy link
Owner Author

Sweet, thank you @flavorjones! 🙌🏼

@marcoroth marcoroth merged commit 361a090 into main Sep 16, 2025
18 checks passed
@marcoroth marcoroth deleted the ruby-utf8-strings branch September 16, 2025 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working c c-extension ruby

Projects

None yet

Development

Successfully merging this pull request may close these issues.

incompatible character encodings with a non-breaking space Render failure using "•" bullet character

2 participants