From 2cd116e4e74ec7566e85b401c20c736a3a74e020 Mon Sep 17 00:00:00 2001 From: macdonst Date: Sat, 23 Apr 2011 08:19:59 +0800 Subject: [PATCH] Issue 60: Contact search unicode problem Contact search was not working for unicode letters. The CallbackServer was changed so that it returned url encode strings. On the JavaScript side the PhoneGap callback handler decodes the returned string. --- framework/assets/js/phonegap.js.base | 5 +++-- framework/src/com/phonegap/CallbackServer.java | 6 +++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/framework/assets/js/phonegap.js.base b/framework/assets/js/phonegap.js.base index 98966d62..2bcdbc52 100755 --- a/framework/assets/js/phonegap.js.base +++ b/framework/assets/js/phonegap.js.base @@ -760,7 +760,8 @@ PhoneGap.JSCallback = function() { // If callback has JavaScript statement to execute if (xmlhttp.status === 200) { - var msg = xmlhttp.responseText; + // Need to url decode the response and replace %20 with a space + var msg = decodeURIComponent(xmlhttp.responseText.replace(/\+/g, '%20')); setTimeout(function() { try { var t = eval(msg); @@ -919,7 +920,6 @@ PhoneGap.includeJavascript = function(jsfile, successCallback) { id.appendChild(el); }; - /** * This class is provided to bridge the gap between the way plugins were setup in 0.9.3 and 0.9.4. * Users should be calling navigator.add.addService() instead of PluginManager.addService(). @@ -931,4 +931,5 @@ var PluginManager = { navigator.app.addService(serviceType, className); } }; + }; diff --git a/framework/src/com/phonegap/CallbackServer.java b/framework/src/com/phonegap/CallbackServer.java index 2fce8a1e..859ac40a 100755 --- a/framework/src/com/phonegap/CallbackServer.java +++ b/framework/src/com/phonegap/CallbackServer.java @@ -13,6 +13,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.ServerSocket; import java.net.Socket; +import java.net.URLEncoder; import java.util.LinkedList; /** @@ -221,7 +222,10 @@ public class CallbackServer implements Runnable { } else { //System.out.println("CallbackServer -- sending item"); - response = "HTTP/1.1 200 OK\r\n\r\n"+this.getJavascript(); + response = "HTTP/1.1 200 OK\r\n\r\n"; + String js = this.getJavascript(); + if (js != null) + response += URLEncoder.encode(js, "UTF-8"); } } else {