DrChanimal
DrChanimal

Reputation: 681

Rails 3 ActiveResource not escaping unicode in xml when sending request

We recently moved to rails 3.2.13. We use ActiveResource to call a web service. ActiveResoure will generate the xml payload. We noticed that the new xml doesn't escape unicode character. For example:

  <name> C:\Documents and Settings\All Users\testütestdev1.txt </name>

In rails 2.3, it will escape ü to &#252; :

  <name> C:\Documents and Settings\All Users\test&#252;testdev1.txt <name>

After some investigation. It looks like it is due to ActiveSuppport to_xml method which doesn't escape unicode character. Has anyone had this issue and know how to solve it?

Upvotes: 0

Views: 234

Answers (1)

shime
shime

Reputation: 9018

You could use Rack::Utils for that

> Rack::Utils.escape("  <name> C:\Documents and Settings\All Users\testütestdev1.txt </name>")
#=> "++%3Cname%3E+C%3ADocuments+and+SettingsAll+Users%09est%C3%BCtestdev1.txt+%3C%2Fname%3E"

> Rack::Utils.unescape(_)
#=> "  <name> C:Documents and SettingsAll Users\testütestdev1.txt </name>"

Upvotes: 1

Related Questions