-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix: Honour encoding in IO::Memory#to_s
#11875
Fix: Honour encoding in IO::Memory#to_s
#11875
Conversation
@@ -393,7 +393,11 @@ class IO::Memory < IO | |||
# ``` | |||
def to_s : String | |||
if encoding = @encoding | |||
String.new to_slice, encoding: encoding.name, invalid: encoding.invalid | |||
{% if flag?(:without_iconv) %} | |||
raise NotImplementedError.new("String.encode") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be better to move this check into the String.encode
method instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wondered about that. But String.encode
is explicit about being for encoding purposes. Calling that method with -Dwithout_iconv
should lead to a compile time error. IO::Memory#to_s
on the other hand is not explicitly about encoding. It's just something that it needs to do in some state. In this case there should definitely not be a compile time error. So raising the runtime error here makes more sense IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @straight-shoota 🙏
Resolves #11015