gleber/erlcloud — pull request #26 by pnc (2013-01-28 18:02:04+00:00)
Title: Add UTF-8 support by using Erlang's unicode application

This patch fixes an error triggered when erlcloud encodes Unicode strings with multibyte characters (the example string here contains a fleuron, if for some reason you get a box instead):

(app@127.0.0.1)1> erlcloud_sdb:put_attributes("test_domain", "test", [{"test", "fleuron: ❦"}]).
** exception error: no function clause matching erlcloud_http:url_encode([10086],"02%A3%noruelf") (src/erlcloud_http.erl, line 17)
in function erlcloud_http:'-make_query_string/1-lc$^0/1-0-'/1 (src/erlcloud_http.erl, line 5)
in call from erlcloud_http:'-make_query_string/1-lc$^0/1-0-'/1 (src/erlcloud_http.erl, line 6)
in call from erlcloud_http:make_query_string/1 (src/erlcloud_http.erl, line 5)
in call from erlcloud_aws:aws_request2/7 (src/erlcloud_aws.erl, line 62)
in call from erlcloud_aws:aws_request/7 (src/erlcloud_aws.erl, line 38)
in call from erlcloud_aws:aws_request_xml/5 (src/erlcloud_aws.erl, line 11)
in call from erlcloud_sdb:sdb_request/3 (src/erlcloud_sdb.erl, line 258)

This patch resolves the error:

(app@127.0.0.1)1> erlcloud_sdb:put_attributes("test_domain", "test", [{"test", "fleuron: ❦"}]).
[{box_usage,2.19909e-5}]

The attribute is then stored and returned as a Erlang Unicode string, as expected:

(app@127.0.0.1)3> erlcloud_sdb:get_attributes("test_domain", "test").
[{attributes,[{"test",[102,108,101,117,114,111,110,58,32,10086]}]},

Unfortunately I wasn't able to get the test suite to run. Am I doing it wrong?

$ make eunit
==> meck (compile)
==> jsx (compile)
==> erlcloud (compile)
Compiled src/erlcloud_sdb.erl
Compiled src/erlcloud_xml.erl
Compiled src/erlcloud_sqs.erl
Compiled src/erlcloud_mon.erl
Compiled src/erlcloud_elb.erl
Compiled src/erlcloud_s3.erl
Compiled src/erlcloud_aws.erl
Compiled src/erlcloud_mturk.erl
Compiled src/erlcloud_ec2.erl
==> erlcloud (eunit)
Compiled src/erlcloud_xml.erl
Compiled src/erlcloud_sdb.erl
Compiled src/erlcloud_sqs.erl
Compiled src/erlcloud_mon.erl
Compiled src/erlcloud_elb.erl
Compiled src/erlcloud_s3.erl
Compiled src/erlcloud_ec2.erl
Compiled src/erlcloud_aws.erl
Compiled src/erlcloud_mturk.erl
undefined
*** instantiation of subtests failed ***
::{badmatch,{ok,{https,[],"host",443,"/",
"?AWSAccessKeyId=id&SignatureMethod=HmacSHA1&SignatureVersion=2&Timestamp=2013-01-28T17%3A42%3A58Z&Signature=KsJhlIBt3CLy86veVgF2P59sd3g%3D"}}}

undefined
*** context setup failed ***
::{already_started,<0.332.0>}

undefined
*** context setup failed ***
::{already_started,<0.332.0>}