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

ASCII-8bit encoding errors raises wrong class of exception #829

Closed
ConradIrwin opened this issue Jun 27, 2013 · 3 comments
Closed

ASCII-8bit encoding errors raises wrong class of exception #829

ConradIrwin opened this issue Jun 27, 2013 · 3 comments

Comments

@ConradIrwin
Copy link
Contributor

"\xc3".force_encoding('ascii-8bit').encode('utf-8') should raise:
Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8

However, in @tychobrailleur 's 0b8d74b it was changed to be Encoding::ConverterNotFoundError: code converter not found (ASCII-8BIT to UTF-8).

This broke the mail gem's handling of bad encodings on jruby-1.7.4 in ruby1.9 mode. Compare https://travis-ci.org/mikel/mail/jobs/8490907 and https://travis-ci.org/mikel/mail/jobs/7941638

@BanzaiMan
Copy link
Member

Looks like this case was just pulled to RubySpec: rubyspec/rubyspec#146

@headius
Copy link
Member

headius commented Jul 25, 2013

This has improved with the new CharsetTranscoder, but it still raises an incorrect error:

$ jruby -e '"\xc3".force_encoding("ascii-8bit").encode("utf-8")'
Encoding::InvalidByteSequenceError: ""\xC3"" on US-ASCII
  encode at org/jruby/RubyString.java:7619
  (root) at -e:1

This error is raised because the only way I could get Java transcoding logic to reject the high bytes of ASCII-8BIT was to require that they be in US-ASCII range...but that causes it to raise an "invalid" error rather than an "undefined" error.

Senjai pushed a commit to StemboltHQ/ruby-openid that referenced this issue Jan 7, 2014
@headius
Copy link
Member

headius commented Nov 12, 2014

Fixed in 9k.

$ jruby -e '"\xc3".force_encoding("ascii-8bit").encode("utf-8")'
Encoding::UndefinedConversionError: "\xC3" from ASCII-8BIT to UTF-8
      encode at org/jruby/RubyString.java:6231
  __script__ at -e:1

@headius headius closed this as completed Nov 12, 2014
@headius headius added this to the JRuby 9.0.0.0-pre1 milestone Nov 12, 2014
@headius headius self-assigned this Nov 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants