encoding issues with chienese chars

28 views
Skip to first unread message

Tal Palant

unread,
Jul 20, 2015, 9:02:36 AM7/20/15
to ring-c...@googlegroups.com
Hi,

i have clojure application using ring that receives a parameter as url encoded like this:

%5B%5B%3Acampaign%20%5B%222015-03-17%20%20%E7%BE%8E%E5%A5%B3%E5%96%9C%E7%88%B1%E7%9A%84%E6%89%8B%E6%B8%B8ios%22%5D%5D%5D

which is:

[[:campaign ["2015-03-17  美女喜爱的手游ios"]]]

when i print it in the end point i get:

2015-03-17  ???????ios\\\

any idea what can be the case?

is there way to change the default encoding used by Ring?

James Reeves

unread,
Jul 20, 2015, 9:37:58 AM7/20/15
to ring-c...@googlegroups.com
There are two encodings you need to get right here. The encoding you use to decode the query string, and the encoding you use to display it.

The wrap-params middleware defaults to UTF-8 to decode the query string, or if there is an encoding specified in the request content-type header, it uses that instead. The encoding can be forced with the :encoding option:

    (wrap-params handler {:encoding "UTF-8"})

The query string you supply seems to decode fine by default:

    user=> (:query-params (params-request {:query-string "x=%5B%5B%3Acampaign%20%5B%222015-03-17%20%20%E7%BE%8E%E5%A5%B3%E5%96%9C%E7%88%B1%E7%9A%84%E6%89%8B%E6%B8%B8ios%22%5D%5D%5D"}))
    {"x" "[[:campaign [\"2015-03-17  美女喜爱的手游ios\"]]]"}

So perhaps the problem is your encoding of your response. You mention printing it, so do you mean you're printing it to the console, or sending it in a response. If it's the latter, you need to ensure that the content-type of the response has the right encoding.

- James

--
You received this message because you are subscribed to the Google Groups "Ring" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ring-clojure...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages