[MacRuby] #1310: JSON.parse fails with NSString
#1310: JSON.parse fails with NSString -----------------------------------+---------------------------------------- Reporter: isaackearse@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.11 Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- {{{ macirb --simple-prompt
require 'json' => true JSON.parse '{}' => {} JSON.parse NSString.stringWithString '{}' NoMethodError: undefined method `encode' for "{}":String
JSON.parse String NSString.stringWithString '{}' => {}
}}}
-- Ticket URL: <http://www.macruby.org/trac/ticket/1310> MacRuby <http://macruby.org/>
#1310: JSON.parse fails with NSString -----------------------------------+---------------------------------------- Reporter: isaackearse@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Changes (by lsansonetti@…): * milestone: MacRuby 0.11 => Comment: Bug or not a bug? We could modify the json library to not use #encode on NSStrings. Or we could force users of the json library to not pass NSStrings. 1 makes more sense as the goal of MacRuby is to not worry people with object conversions. -- Ticket URL: <http://www.macruby.org/trac/ticket/1310#comment:1> MacRuby <http://macruby.org/>
#1310: JSON.parse fails with NSString -----------------------------------+---------------------------------------- Reporter: isaackearse@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Comment(by jballanc@…): My feeling is that this is not a bug, but it also reemphasizes the need to figure out what to do about distinguishing NSStrings from Strings or coercing from one to the other -- Ticket URL: <http://www.macruby.org/trac/ticket/1310#comment:2> MacRuby <http://macruby.org/>
#1310: JSON.parse fails with NSString -----------------------------------+---------------------------------------- Reporter: isaackearse@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Comment(by isaackearse@…): I guess this is more of a feature request than a bug. I think we should modify the json library to not use #encode on NSStrings. Is there an easy way to distinguish a String from an NSString? -- Ticket URL: <http://www.macruby.org/trac/ticket/1310#comment:3> MacRuby <http://macruby.org/>
#1310: JSON.parse fails with NSString -----------------------------------+---------------------------------------- Reporter: isaackearse@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Comment(by watson1978@…): Maybe, {{{ #!diff diff --git a/ext/json/parser/parser.rl b/ext/json/parser/parser.rl index 5862698..1251c63 100644 --- a/ext/json/parser/parser.rl +++ b/ext/json/parser/parser.rl @@ -1,4 +1,5 @@ #include "parser.h" +RUBY_EXTERN VALUE rb_cRubyString; /* unicode */ @@ -634,7 +635,11 @@ static VALUE cParser_initialize(int argc, VALUE *argv, VALUE self) VALUE source, opts; GET_PARSER; rb_scan_args(argc, argv, "11", &source, &opts); - source = convert_encoding(StringValue(source)); + StringValue(source); + if (CLASS_OF(source) == rb_cRubyString) { + // MacRuby : convert only RubyString + source = convert_encoding(source); + } ptr = RSTRING_PTR(source); len = RSTRING_LEN(source); if (!NIL_P(opts)) { }}} create parser.c {{{ $ ragel parser.rl }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1310#comment:4> MacRuby <http://macruby.org/>
#1310: JSON.parse fails with NSString -----------------------------------+---------------------------------------- Reporter: isaackearse@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Comment(by lsansonetti@…): I am wondering if we shouldn't add a dummy #encode function to NSString. -- Ticket URL: <http://www.macruby.org/trac/ticket/1310#comment:5> MacRuby <http://macruby.org/>
#1310: JSON.parse fails with NSString -----------------------------------+---------------------------------------- Reporter: isaackearse@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Comment(by lsansonetti@…): Per yesterday's discussion, let's add NSString#encode, which works as expected, and NSString#encode!, which raises an exception. -- Ticket URL: <http://www.macruby.org/trac/ticket/1310#comment:6> MacRuby <http://macruby.org/>
#1310: JSON.parse fails with NSString -----------------------------------+---------------------------------------- Reporter: isaackearse@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.11 Component: MacRuby | Resolution: fixed Keywords: | -----------------------------------+---------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.11 Comment: Done as https://github.com/MacRuby/MacRuby/commit/d178850ccd4ff2ceef60323811b710a496.... -- Ticket URL: <http://www.macruby.org/trac/ticket/1310#comment:7> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby