[MacRuby] #1268: force_encoding on NSStrings with Net::HTTP
#1268: force_encoding on NSStrings with Net::HTTP -----------------------------------+---------------------------------------- Reporter: eric@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- There is a previous, closed ticket, #689, in regards to this exact same issue. Apparently there was some regression, or some new code within Net::HTTP has reopened this, but in both 0.10 and 0.11 with the gazette gem, and as well as with a pure Net::HTTP.post_form call, I get this error. -- Ticket URL: <http://www.macruby.org/trac/ticket/1268> MacRuby <http://macruby.org/>
#1268: force_encoding on NSStrings with Net::HTTP -----------------------------------+---------------------------------------- Reporter: eric@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Comment(by eric@…): Particular instance with the gazette gem was: {{{ client.add(self.url, :title => self.title) }}} However, with the guidance of alloy via IRC, the following code was used (which does work): {{{ client.add(String.new(NSString.stringWithString(self.url)), :title => String.new(NSString.stringWithString(self.title))) }}} In the case of Net::HTTP, the following (example) setup was attempted: {{{ require 'net/http' def call_api url = URI.parse("#{HOST}/api/call.json") arguments = { 'email' => self.email, 'foo' => self.bar } resp, data = Net::HTTP.post_form(url, arguments) end }}} While another method has already been utilized, I am fairly positive that the previous fix would be applicable here as well. -- Ticket URL: <http://www.macruby.org/trac/ticket/1268#comment:1> MacRuby <http://macruby.org/>
#1268: force_encoding on NSStrings with Net::HTTP -----------------------------------+---------------------------------------- Reporter: eric@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Comment(by eloy.de.enige@…): Like already discussed with Eric on irc, but adding here for completeness sake, the use of NSString.stringWithString() was only so I could create a NSString instance and ins't needed for this workaround. -- Ticket URL: <http://www.macruby.org/trac/ticket/1268#comment:2> MacRuby <http://macruby.org/>
#1268: force_encoding on NSStrings with Net::HTTP -----------------------------------+---------------------------------------- Reporter: eric@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -----------------------------------+---------------------------------------- Comment(by lsansonetti@…): #force_encoding will not be implemented on NSStrings. The #String method can be used to return a RubyString. However, if net/http is using #force_encoding on a given string without making a copy, then it may be a problem that we can fix in net/http itself. -- Ticket URL: <http://www.macruby.org/trac/ticket/1268#comment:3> MacRuby <http://macruby.org/>
#1268: force_encoding on NSStrings with Net::HTTP -----------------------------------+---------------------------------------- Reporter: eric@… | 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: I had a quick look and realized that NSString#dup returns a NSString copy, therefore s.dup.force_encoding(...) will not work on NSStrings. I changed NSString#dup to return a RubyString in https://github.com/MacRuby/MacRuby/commit/3e200e8341a17797c8af79d7b781372a27... and this should fix the problem. -- Ticket URL: <http://www.macruby.org/trac/ticket/1268#comment:4> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby