Skip to content
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

"invalid byte sequence in UTF-8" after String#encode!; behavior differs from MRI (JRuby-1.7.13) #1900

Closed
lenny opened this issue Aug 13, 2014 · 1 comment
Milestone

Comments

@lenny
Copy link

lenny commented Aug 13, 2014

1.9.3-p385 :007 > "\xE6".encoding
 => #<Encoding:UTF-8> 
1.9.3-p385 :008 > "\xE6".valid_encoding?
 => false 
1.9.3-p385 :009 > "\xE6".encode!('UTF-8', 'BINARY', :invalid => :replace, :undef => :replace).valid_encoding?
 => true 
1.9.3-p385 :013 > "\xE6".encode!('UTF-8', 'BINARY', :invalid => :replace, :undef => :replace).match(/\S/)
 => #<MatchData "�"> 
jruby-1.7.13 :016 >  "\xE6".encoding
 => #<Encoding:UTF-8> 
jruby-1.7.13 :017 > "\xE6".valid_encoding?
 => false 
jruby-1.7.13 :018 > "\xE6".encode!('UTF-8', 'BINARY', :invalid => :replace, :undef => :replace).valid_encoding?
 => false 
jruby-1.7.13 :042 > "\xE6".encode!('UTF-8', 'BINARY', :invalid => :replace, :undef => :replace).match(/\S/)
ArgumentError: invalid byte sequence in UTF-8
    from org/jruby/RubyRegexp.java:1697:in `match'
    from org/jruby/RubyString.java:1734:in `match'
    from (irb):42:in `evaluate'
    from org/jruby/RubyKernel.java:1101:in `eval'
    from org/jruby/RubyKernel.java:1501:in `loop'
    from org/jruby/RubyKernel.java:1264:in `catch'
    from org/jruby/RubyKernel.java:1264:in `catch'
    from /Users/Shared/lenny/.rvm/rubies/jruby-1.7.13/bin/jirb:13:in `(root)'
jruby-1.7.13 :043 > 

encode as opposed to #encode! works as expected

jruby-1.7.13 :044 > "\xE6".encode('UTF-8', 'BINARY', :invalid => :replace, :undef => :replace).valid_encoding?
 => true 
jruby-1.7.13 :045 > "\xE6".encode('UTF-8', 'BINARY', :invalid => :replace, :undef => :replace).match(/\S/)
 => #<MatchData "�"> 
@rtyler
Copy link

rtyler commented Aug 7, 2015

This has been fixed at least as of JRuby 9k

[7] pry(main)> "\xE6".encoding
=> #<Encoding:UTF-8>
[8] pry(main)> "\xE6".valid_encoding?
=> false
[9] pry(main)> "\xE6".encode!('UTF-8', 'BINARY', :invalid => :replace, :undef => :replace).valid_encoding?
=> true
[10] pry(main)> "\xE6".encode!('UTF-8', 'BINARY', :invalid => :replace, :undef => :replace).match(/\S/)
=> #<MatchData "�">
[11] pry(main)> JRUBY_VERSION
=> "9.0.0.0"
[12] pry(main)> 

@rtyler rtyler closed this as completed Aug 7, 2015
@enebo enebo added this to the JRuby 9.0.1.0 milestone Aug 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants