0

I am working on iOS7 with RubyMotion 2.34, Motion-bundler 0.2.1, and rubysl-rexml 2.4.1.

I've gotten the following error when trying to parse an XML response from a server, down in the encoding part of REXML. However, I've also done the following to isolate the problem, which is what REXML library does to the string it is given:

def content
    @s = @response.body.to_s
    puts @s.encoding
    @s.encode("UTF-8")
end

where @response is the return from AFMotion::HTTP.get("http://....") call. It's just a simple XML string with nothing but plain US-ASCII characters in it. I get the following error:

2014-10-02 18:34:14.714 promotion-motion-kit[44375:1346884] *** Terminating app due to uncaught exception 'RuntimeError', reason: 'http_client.rb:17:in block in content': this operation cannot be performed with encodingUTF-8' because Apple's ICU does not support it (RuntimeError) from http_client.rb:15:in `content'

I also get the EXACT same error (noting the UTF-8) when I change the code to:

@s.encode("US-ASCII")

So, it seems that it does not matter what I give String#encode as long as it is a valid encoding name.

UPDATE: This error raises with ANY string I use, such as:

"hello".encode("UTF-8")

Doesn't anybody know how to rectify this situation?

Dr. Polar Humenn
  • 377
  • 3
  • 10
  • I'm getting this exact same problem. Was trying to get REXML working, but you're right, happens with any string, such as `'x'.encode`. Did you find a solution? – Brett Feb 08 '15 at 15:19
  • @Brett No, I did not. I gave up on REXML and used a Coca library. However, after so many problems, I gave up on Rubymotion altogether. [link](http://polarworkingnotes.blogspot.com/2015/02/the-rubymotion-failure.html) – Dr. Polar Humenn Feb 09 '15 at 18:20

1 Answers1

1

Ack, sorry to hear that. I still prefer working with RubyMotion over raw Objective-C.

Although I don't have a perfect solution, I have a decent workaround, at least in my case. For me, 99.9% of my input will already be in utf8 format, and the string will show that it has that encoding. So I've overridden the encode method to check for that case.

class String alias_method :orig_encode, :encode def encode(encoding) return self if self.encoding.to_s == encoding orig_encode(encoding) end end

Also, the method String.force_encoding('UTF-8') also works, though as I understand it, if there is an actual error during the encoding, the error doesn't get raised (as it would in the normal encode method). But depending on your usage, that may be ok.

At least for me, this should work until RubyMotion gets this (what I consider) bug fixed.

Brett
  • 191
  • 1
  • 1
  • 5
  • Seems reasonable. I ditched the rubysl-rexml package and used an REXML Cocapod and the problem went away. Then I gave up on Rubymotion all together because of horrible memory problems. – Dr. Polar Humenn Mar 05 '15 at 14:20