Issue Type: Bug Bug
Assignee: Thomas E Enebo
Created: 28/Sep/12 1:31 AM
Description:

The following code always fails ("failed 2") on all versions of jruby but runs without a raise on MRI 1.9.3:

W252 = Encoding::WINDOWS_1252
ISO8 = Encoding::ISO_8859_1
UTF8 = Encoding::UTF_8

s1 = 0x201C.chr( UTF8 ).force_encoding( ISO8 ).encode( UTF8 )
raise "failed 1" unless s1[ 1 ] == 0x80.chr( UTF8 )

s2 = 0x201C.chr( UTF8 ).force_encoding( W252 ).encode( UTF8 )
raise "failed 2" unless s2[ 1 ] == 0x20AC.chr( UTF8 )

This is order dependent. It will not fail if the s2 lines are moved above the s1 lines.

The following further demonstrates the order dependency by failing half the time on jruby and always succeeding on MRI:

W252 = Encoding::WINDOWS_1252
ISO8 = Encoding::ISO_8859_1
UTF8 = Encoding::UTF_8

[ W252, ISO8 ].shuffle.each do |a_encoding|
  c = 0x201C.chr( UTF8 ).force_encoding( a_encoding ).encode( UTF8 )
  puts c
  mchar = ( a_encoding == W252 ) ? 0x20AC : 0x80
  raise "failed with #{a_encoding}" unless c[1] == mchar.chr( UTF8 )
end

If this seems a bit contrived, see

https://github.com/dekellum/mojibake

for how I bumped into it.

Environment: Can be reproduced on all of the following tried:

jruby 1.6.5 (ruby-1.9.2-p136) (2011-10-25 9dcd388) (Java HotSpot(TM) Server VM 1.7.0_07) [linux-i386-java]
jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) Server VM 1.7.0_07) [linux-i386-java]
jruby 1.6.8 (ruby-1.9.2-p312) (2012-09-18 1772b40) (Java HotSpot(TM) Server VM 1.7.0_07) [linux-i386-java]
jruby 1.7.0.RC1 (1.9.3p203) 2012-09-25 8e849de on Java HotSpot(TM) Server VM 1.7.0_07-b10 [linux-i386]

But not: ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
Project: JRuby
Priority: Major Major
Reporter: David Kellum
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to