Bug #5232
closedEncoding of Date#to_s
Description
The encoding of Date#to_s should respect Encoding.default_internal.
Here is the behavior today:
irb(main):001:0> require 'date'
=> true
irb(main):002:0> Date.today.to_s.encoding
=> #Encoding:US-ASCII
irb(main):003:0> Encoding.default_internal = Encoding::UTF_8
=> #Encoding:UTF-8
irb(main):004:0> Date.today.to_s.encoding
=> #Encoding:US-ASCII
irb(main):005:0>
Here is the behavior I expect:
irb(main):001:0> require 'date'
=> true
irb(main):002:0> Date.today.to_s.encoding
=> #Encoding:US-ASCII
irb(main):003:0> Encoding.default_internal = Encoding::UTF_8
=> #Encoding:UTF-8
irb(main):004:0> Date.today.to_s.encoding
=> #Encoding:UTF-8
irb(main):005:0>
I've attached a patch that fixes this.
Files
Updated by naruse (Yui NARUSE) over 13 years ago
I doubt that it must be default internal encoding.
When Encoding.default_internal is set, strings should be ASCII-8BIT (its content is binary), US-ASCII,
or default internal encoding.
Is there a reason why you think it should be default internal encoding?
Updated by tenderlovemaking (Aaron Patterson) over 13 years ago
I thought that is what default_internal was used for? If default_internal is set, then strings should be automatically transcoded to that encoding.
It seems strange that if I (as a ruby programmer) request that strings be UTF-8 (by setting default internal), they are returned as another encoding.
Updated by tenderlovemaking (Aaron Patterson) over 13 years ago
I think what I'm trying to say is: why does US-ASCII play a role?
It seems if someone sets default_internal, then strings should either be ASCII-8BIT or default_internal.
Updated by naruse (Yui NARUSE) over 13 years ago
US-ASCII is used for ASCII only strings.
It means pure string in some means.
default internal encoding is used for non ASCII non BINARY strings.
The basis of these is that ASCII is special.
Updated by tadf (tadayoshi funaba) over 13 years ago
- Status changed from Open to Rejected
why date?
Encoding.default_internal = Encoding::UTF_8
#=> #Encoding:UTF-8
99e99.to_s.encoding
#=> #Encoding:US-ASCII
what's the difference?
this is not a matter of date, anyway.
Updated by naruse (Yui NARUSE) over 13 years ago
tadayoshi funaba wrote:
why date?
Encoding.default_internal = Encoding::UTF_8
#=> #Encoding:UTF-8
99e99.to_s.encoding
#=> #Encoding:US-ASCIIwhat's the difference?
this is not a matter of date, anyway.
Yeah, even if Aaron's suggest is reasonable, it is the whale Ruby's issue;
This is not correct ticket about it.