Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Incomplete
-
Affects Version/s: JRuby 1.6.5
-
Fix Version/s: None
-
Component/s: Ruby 1.9.2
-
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)
-
Number of attachments :
Description
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'))
#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.
There's a good chance this is fixed on master and jruby-1_6 branches. Can you re-test with a build from http://ci.jruby.org/snapshots?