Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

jruby-json: json/ext makes incorrect assumptions about character encoding #101

Closed
perlun opened this Issue · 5 comments

4 participants

@perlun

Hi!

If I run "my_object.to_json", using "require 'json/ext'" (on JRuby 1.6.4, in Ruby 1.9 mode), I get output which is encoded as UTF-8 - even though my JVM is running with Windows-1252. This causes problems, because the output is later on encoded as UTF-8 again (it gets sent as the output from a servlet). Hence, it gets double-encoded and all non-ASCII characters are scrambled.

(This can easily be seen/tested on Windows where the JVM default encoding is normally not UTF-8, but Windows-1252. I guess the default on Linux is UTF-8, which could describe why the bug hasn't been seen earlier.)

The behavior is correct when using json/pure => it seems to be related specifically to the json/ext

I am using json-1.5.0-java.

Best regards,
Per Lundberg

@carlhoerberg

json/ext behaves differently regarding encoding on linux and mac os as well:

 $ jruby -v
 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] 
 $ jruby -e 'require "json/ext"; h = {"å"=>1}; puts h.to_json.encoding'
 ASCII-8BIT
 $ jruby -e 'require "json/pure"; h = {"å"=>1}; puts h.to_json.encoding'
 UTF-8
@plentz

I almost sure that this bug is also solved by #119. Related/test case proving it's solved in #126 (ps: you need to use json gem version 1.6.6)

@carlhoerberg
$ jruby -v
jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) Client VM 1.6.0_29) [darwin-i386-java]

$ jruby -e 'require "json/pure"; h = {"å"=>1}; puts h.to_json.encoding; puts JSON::VERSION'
UTF-8
1.6.6

$ jruby -e 'require "json/ext"; h = {"å"=>1}; puts h.to_json.encoding; puts JSON::VERSION'
ASCII-8BIT
1.6.6
@plentz

@carlhoerberg you're right, sorry. I just created a testcase to reproduce it and referenced it in intridea/multi_json#25 too.

@plentz plentz referenced this issue from a commit in tautt/jruby_report
@plentz plentz adding test for flori/json#101 cbecc99
@plentz plentz referenced this issue in intridea/multi_json
Closed

encoding issues with jruby #25

@flori flori closed this
@plentz

great!

@plentz plentz referenced this issue from a commit in tautt/jruby_report
@plentz plentz fixed by flori/json#101 06c947e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.