Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 345309

Summary: [Help] Web API JSON format should be encoded
Product: [Eclipse Project] Platform Reporter: Chris Austin <ChrisAustin>
Component: User AssistanceAssignee: platform-ua-inbox <platform-ua-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: cgold, ChrisAustin, snehpaul
Version: 3.7Flags: cgold: review+
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
JSON Fixes none

Description Chris Austin CLA 2011-05-10 14:19:34 EDT
Sometimes JSON data values contains a value with some special characters, which
are a part of JSON structure. Then client JSON parser not able to read JSON
correctly.
Now all value field's are encode using the JAVA encoding:
java.net.URLEncoder.encode(val, "UTF-8")

All web Client should decode the values while reading JSON data using the
custom JavaScript decode method:

decode = function(str) {
    str = '' + str;
    str = str.replace(/\+/g, " ");
    str = str.replace(/%7E/g, "~");
    str = str.replace(/%21/g, "!");
    str = str.replace(/%27/g, "'");
    str = str.replace(/%28/g, "(");
    str = str.replace(/%29/g, ")");

    return decodeURIComponent(str);
}

And Java client should use:
java.net.URLDecoder.decode(val, "UTF-8")
Comment 1 Chris Austin CLA 2011-05-10 14:23:35 EDT
Created attachment 195255 [details]
JSON Fixes

Adding Snehasish's patch.
Comment 2 Chris Austin CLA 2011-05-10 15:56:11 EDT
The patch looks good - values are encoded.  However, the decode function described only decodes a handful of characters.  Many other special characters are encoded in the return data, so you need to decode all of them for an accurate read.
Comment 3 Chris Austin CLA 2011-05-10 15:58:49 EDT
(In reply to comment #2)
> The patch looks good - values are encoded.  However, the decode function
> described only decodes a handful of characters.  Many other special characters
> are encoded in the return data, so you need to decode all of them for an
> accurate read.

Sorry - missed the last line: return decodeURIComponent(str);
If decodeURIComponent(str) takes care of the rest of the special characters, I think we may be all set.
Comment 4 Chris Goldthorpe CLA 2011-05-10 16:38:12 EDT
Patch looks good to me also, committed to HEAD.