summaryrefslogtreecommitdiff
path: root/lib/js
diff options
context:
space:
mode:
authorT Jake Luciani <jake@apache.org>2010-09-17 23:38:25 +0000
committerT Jake Luciani <jake@apache.org>2010-09-17 23:38:25 +0000
commit416eea9802d16645d4f4da8909abee5b4b51d95e (patch)
tree1064cf63968ea84a2155055281d583bb4a3c76f3 /lib/js
parent83c47958707956a8812b2c5c91a4550f874cb055 (diff)
downloadthrift-416eea9802d16645d4f4da8909abee5b4b51d95e.tar.gz
THRIFT-885: fix string encoding
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@998371 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'lib/js')
-rw-r--r--lib/js/thrift.js45
1 files changed, 39 insertions, 6 deletions
diff --git a/lib/js/thrift.js b/lib/js/thrift.js
index f048dbffd..9b92658d0 100644
--- a/lib/js/thrift.js
+++ b/lib/js/thrift.js
@@ -169,13 +169,13 @@ Thrift.Transport.prototype = {
//Gets the browser specific XmlHttpRequest Object
getXmlHttpRequestObject : function() {
-
+
try { return new XMLHttpRequest() } catch(e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP") } catch (e) {}
throw "Your browser doesn't support the XmlHttpRequest object. Try upgrading to Firefox."
-
+
},
flush : function(){
@@ -185,7 +185,7 @@ Thrift.Transport.prototype = {
return this.send_buf;
var xreq = this.getXmlHttpRequestObject()
-
+
if (xreq.overrideMimeType)
xreq.overrideMimeType("application/json")
@@ -451,7 +451,42 @@ Thrift.Protocol.prototype = {
},
writeString : function(str){
- this.tstack.push('"'+encodeURIComponent(str)+'"');
+ // We do not encode uri components for wire transfer:
+ if(str === null) {
+ this.tstack.push(null);
+ } else {
+ // concat may be slower than building a byte buffer
+ var escapedString = "";
+ for(var i = 0; i < str.length; i++) {
+ var ch = str.charAt(i); // a single double quote: "
+ if(ch === '\"') {
+ escapedString += '\\\"'; // write out as: \"
+ } else if(ch === '\\') { // a single backslash: \
+ escapedString += '\\\\'; // write out as: \\
+ /* Currently escaped forward slashes break TJSONProtocol.
+ * As it stands, we can simply pass forward slashes into our strings
+ * across the wire without being escaped.
+ * I think this is the protocol's bug, not thrift.js
+ * } else if(ch === '/') { // a single forward slash: /
+ * escapedString += '\\/'; // write out as \/
+ * }
+ */
+ } else if(ch === '\b') { // a single backspace: invisible
+ escapedString += '\\b'; // write out as: \b"
+ } else if(ch === '\f') { // a single formfeed: invisible
+ escapedString += '\\f'; // write out as: \f"
+ } else if(ch === '\n') { // a single newline: invisible
+ escapedString += '\\n'; // write out as: \n"
+ } else if(ch === '\r') { // a single return: invisible
+ escapedString += '\\r'; // write out as: \r"
+ } else if(ch === '\t') { // a single tab: invisible
+ escapedString += '\\t'; // write out as: \t"
+ } else {
+ escapedString += ch; // Else it need not be escaped
+ }
+ }
+ this.tstack.push('"' + escapedString + '"');
+ }
},
writeBinary : function(str){
@@ -663,8 +698,6 @@ Thrift.Protocol.prototype = {
readString : function(){
var r = this.readI32()
- r["value"] = decodeURIComponent(r["value"])
-
return r
},