From bb4d52a75c0c7e6c2875322835053e48810a20ce Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 3 Jun 2013 11:39:18 +0800 Subject: [PATCH] fixed #2243: XMLHttpRequest don't support non-ascii characters. --- scripting/javascript/bindings/XMLHTTPRequest.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripting/javascript/bindings/XMLHTTPRequest.cpp b/scripting/javascript/bindings/XMLHTTPRequest.cpp index e40ed78299..2e69bea25b 100644 --- a/scripting/javascript/bindings/XMLHTTPRequest.cpp +++ b/scripting/javascript/bindings/XMLHTTPRequest.cpp @@ -628,7 +628,7 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, send) { JSString *str = NULL; - char *data = NULL; + std::string data; // Clean up header map. New request, new headers! http_header.clear(); @@ -636,12 +636,13 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, send) if (!JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &str)) { return JS_FALSE; }; - data = JS_EncodeString(cx, str); + JSStringWrapper strWrap(str); + data = strWrap.get(); } - if (data != NULL && meth.compare("post") == 0 || meth.compare("POST") == 0) { - cc_request->setRequestData(data, strlen(data)); + if (data.length() > 0 && (meth.compare("post") == 0 || meth.compare("POST") == 0)) { + cc_request->setRequestData(data.c_str(), data.length()); } _setHttpRequestHeader(); @@ -700,7 +701,10 @@ JS_BINDED_FUNC_IMPL(MinXmlHttpRequest, getResponseHeader) return JS_FALSE; }; - char *data = JS_EncodeString(cx, header_value); + std::string data; + JSStringWrapper strWrap(header_value); + data = strWrap.get(); + stringstream streamdata; streamdata << data;