Project

General

Profile

Bug #8866

frozen string literal("foo"f ) can ignore source encoding after r42843.

Added by Tomoyuki Chikanaga over 3 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
ruby -v:
ruby 2.1.0dev (2013-09-05 trunk 42844) [x86_64-darwin11.4.2]
[ruby-core:57037]

Description

Hello,

After r42843, frozen string literal can have encoding different from script encoding.

example:

usascii.rb:

coding: us-ascii

def usascii
"foo"f
end

utf8.rb:

coding: utf-8

def utf8
"foo"f
end

$ ruby -r./usascii -r./utf8 -e 'p [usascii.object_id == utf8.object_id, usascii.encoding, utf8.encoding]'
[true, #Encoding:US-ASCII, #Encoding:US-ASCII]
$ ruby -r./utf8 -r./usascii -e 'p [usascii.object_id == utf8.object_id, usascii.encoding, utf8.encoding]'
[true, #Encoding:UTF-8, #Encoding:UTF-8]

It is because fstring_hash_type use rb_str_cmd for compare functions.
rb_str_cmd() treat strings contains only ascii characters with ascii compatible encodings as same strings.

Regards.

Associated revisions

Revision 42847
Added by Charlie Somerville over 3 years ago

  • string.c (fstring_cmp): take string encoding into account when
    comparing fstrings [Bug #8866]

  • test/ruby/test_string.rb: add test

Revision 42847
Added by Charlie Somerville over 3 years ago

  • string.c (fstring_cmp): take string encoding into account when
    comparing fstrings [Bug #8866]

  • test/ruby/test_string.rb: add test

Revision 42847
Added by Charlie Somerville over 3 years ago

  • string.c (fstring_cmp): take string encoding into account when
    comparing fstrings [Bug #8866]

  • test/ruby/test_string.rb: add test

History

#1 Updated by Charlie Somerville over 3 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r42847.
Tomoyuki, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • string.c (fstring_cmp): take string encoding into account when
    comparing fstrings [Bug #8866]

  • test/ruby/test_string.rb: add test

Also available in: Atom PDF