[
https://issues.apache.org/jira/browse/THRIFT-885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12904905#action_12904905
]
Jordan commented on THRIFT-885:
-------------------------------
I just tried removing it and everything works GREAT so far (that I have tested)
except for quotes inside of a string.
In fact, the only reason why this was working at all was because you were using
encodeUriComponent in javascript which escaped the quotes into %22.
The json spec says that Strings should be escaped with a backslash. So in the
current codebase the json objects that are sent across the wire are really only
loose adaptations of the objects they are intended to represent.
To fix this we shouldn't use encodeURIComponent, and instead try to use
properJSON (because that is actually what TJSONProtocol expects anyways)
The two steps involve:
1. simply removing en/decodeUriComponent from thrift.js.
2. Escaping all of the fields that the json spec requires (as opposed to
relying on encodeUriComponent to do it.)
3. Unescaping all of the escaped fields when deserializing.
Number one is dirt simple, numbers two and three I don't really know where to
begin.
See the json documentation on Strings here http://json.org/
> Url encoded strings never get decoded? How do we fix this?
> ----------------------------------------------------------
>
> Key: THRIFT-885
> URL: https://issues.apache.org/jira/browse/THRIFT-885
> Project: Thrift
> Issue Type: Bug
> Reporter: Jordan
>
> This is for the test java server that was written to test the client.
> Suppose you have a method such as testString(theTestString)
> If you call it from the javascript like so:
> client.testString("hello man");
> The string that your server implementation sees will be all crazy and url
> encoded.
> public static void testString(string theTestString) {
> // Inside here that string looks like "hello%20man".
> }
> We need it to be urlencoded when coming across the wire because we're using
> JSON as the protocol, but once it gets to thrift server code, it needs to be
> normal.
> So what's going on here? Inside of strings (of javascript objects) things
> like quotes and spaces are escaped. This is fine, but I do not believe that
> is part of the TJSONProtocol. This is something that is specific to having a
> js thrift client am I right? So where do we fix this?
> I'm not exactly sure what will work, but the following seemed to work mostly
> okay, but there are still bugs. I basically just strip out encoded parts from
> the entire message (even though the problem seems to only exist inside string
> fields.)
> Around line 115.
> <code>
> HttpEntity entity = ((HttpEntityEnclosingRequest)
> request).getEntity();
> byte[] entityContent = EntityUtils.toByteArray(entity);
> String decodedEntityContentString =
> java.net.URLDecoder.decodeURIComponent(new String(entityContent, "UTF-8"));
> byte[] decodedEntityContentBytes =
> decodedEntityContentString.getBytes("UTF-8");
> System.out.println("Incoming content: " + new
> String(entityContent));
> System.out.println("Incoming content
> normalized: " + new String(decodedEntityContentBytes, "UTF-8"));
>
> // This almost works, except escaped quotes
> inside of strings
> final String output =
> this.thriftRequest(decodedEntityContentBytes);
> System.out.println("Outgoing content: "+output);
>
> EntityTemplate body = new EntityTemplate(new
> ContentProducer() {
> </code>
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.