Garrett Motzner created JRUBY-6288: -------------------------------------- Summary: 'incompatible character encodings: ASCII-8BIT and UTF-8' error thrown by jruby but not by ruby Key: JRUBY-6288 URL: https://jira.codehaus.org/browse/JRUBY-6288 Project: JRuby Issue Type: Bug Components: Ruby 1.9.2 Affects Versions: JRuby 1.6.5 Environment: OS X 10.6.8; jruby 1.6.5 (ruby-1.9.2-p136) (2011-10-25 9dcd388) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]; Rails 3.1.3; activerecord-jdbcsqlite3-adapter (1.2.1); activerecord-jdbc-adapter (1.2.1); jdbc-sqlite3 (3.7.2) Reporter: Garrett Motzner Assignee: Thomas E Enebo
When trying to save an activerecord using the jdbcsqlite3-adapter, I get an 'incompatible character encodings: ASCII-8BIT and UTF-8' error. raw stack trace: https://gist.github.com/1491694 string that caused error: "spec/testfiles/chars/arabic/Новая" Looking into the issue myself, I believe the issue is caused by a line similar to: sql.gsub('?'){strings.shift} the encodings of the strings are similar to this pattern: US-ASCII x 4 ASCII-8BIT US-ASCII x 2 ASCII-8BIT x 2 US-ASCII x 12 UTF-8 US-ASCII x2 ASCII-8BIT US-ASCII x 6 I tried to get the strings themselves, but when I did a join(), I got the same error. When I tried to replicate the issue with a similar gsub and set of strings, I could not reproduce the error. My attempt follows: --- usasciistr="Lorem".encode 'US-ASCII' usasciistr.force_encoding('US-ASCII') #just in case that does something more than just encode. Force encoding doesn't do any conversion, unlike encode, but does force the specified encoding type to be set. Does it do anything else? i don't know. ascii8bitstr="Ipsum".encode 'ASCII-8BIT' ascii8bitstr.force_encoding('ASCII-8BIT') utf8str="Новая".encode 'UTF-8' utf8str.force_encoding('UTF-8') sql='(?,?,?,?,?,?)'.encode 'US-ASCII' #because the sql strings seem to be encoded that way sql.force_encoding('US-ASCII') ary=[usasciistr,ascii8bitstr,usasciistr,usasciistr,utf8str,usasciistr] sql.gsub('?'.encode('US-ASCII')){ary.shift} #this is bassically the line of code that throws the error --- I am glad to help solve this issue, and will lend a hand if you need more information. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://jira.codehaus.org/secure/ContactAdministrators!default.jspa 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