From 2508e71a4485c482b9866c0e68956f111a9517b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Fri, 23 Dec 2011 15:15:19 +0200 Subject: [PATCH 1/6] Supposedly fix for #354 in support.openlp.org, a traceback when JSON response from remote cannot be decoded. --- openlp/plugins/remotes/lib/httpserver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 0da445ede..345550f30 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -332,7 +332,12 @@ class HttpConnection(object): args = [] for param in match.groups(): args.append(param) - response = func(*args) + try: + response = func(*args) + except ValueError as error: + log.exception(u'Error while decoding JSON message ' + 'from remote browser.') + return False break if response: self.send_response(response) From 706fa7ff497ea674797b566b00d617109b7e91cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Fri, 23 Dec 2011 16:54:08 +0200 Subject: [PATCH 2/6] Revert previous change. --- openlp/plugins/remotes/lib/httpserver.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 345550f30..0da445ede 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -332,12 +332,7 @@ class HttpConnection(object): args = [] for param in match.groups(): args.append(param) - try: - response = func(*args) - except ValueError as error: - log.exception(u'Error while decoding JSON message ' - 'from remote browser.') - return False + response = func(*args) break if response: self.send_response(response) From 7f6edda46321c8160bd051f128735fa5d6aacdf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Fri, 23 Dec 2011 16:54:53 +0200 Subject: [PATCH 3/6] Add a missing pair of quotes to fix #354. --- openlp/plugins/remotes/html/openlp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index 0972a6637..684c77467 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -208,7 +208,7 @@ window.OpenLP = { }, showAlert: function (event) { event.preventDefault(); - var text = "{\"request\": {\"text\": " + $("#alert-text").val() + "}}"; + var text = "{\"request\": {\"text\": \"" + $("#alert-text").val() + "\"}}"; $.getJSON( "/api/alert", {"data": text}, From e94ab832eb58b07ab9e99a75ef5e24b25bba5344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Fri, 23 Dec 2011 17:23:32 +0200 Subject: [PATCH 4/6] Escape \ and " characters first, to prevent traceback when sending such an alert from remote. --- openlp/plugins/remotes/html/openlp.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index 684c77467..8e4f1cbfc 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -208,7 +208,9 @@ window.OpenLP = { }, showAlert: function (event) { event.preventDefault(); - var text = "{\"request\": {\"text\": \"" + $("#alert-text").val() + "\"}}"; + var text = "{\"request\": {\"text\": \"" + + $("#alert-text").val().replace("\\", "\\\\").replace("\"", "\\\"") + + "\"}}"; $.getJSON( "/api/alert", {"data": text}, @@ -219,7 +221,9 @@ window.OpenLP = { }, search: function (event) { event.preventDefault(); - var text = "{\"request\": {\"text\": \"" + $("#search-text").val() + "\"}}"; + var text = "{\"request\": {\"text\": \"" + + $("#search-text").val().replace("\\", "\\\\").replace("\"", "\\\"") + + "\"}}"; $.getJSON( "/api/" + $("#search-plugin").val() + "/search", {"data": text}, From 514773abe85bbc7dfcb7fc71906344ee1fdff072 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Fri, 23 Dec 2011 17:47:36 +0200 Subject: [PATCH 5/6] Make replace work for two or more occurrences. --- openlp/plugins/remotes/html/openlp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index 8e4f1cbfc..5c991a018 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -209,7 +209,7 @@ window.OpenLP = { showAlert: function (event) { event.preventDefault(); var text = "{\"request\": {\"text\": \"" + - $("#alert-text").val().replace("\\", "\\\\").replace("\"", "\\\"") + + $("#alert-text").val().replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"}}"; $.getJSON( "/api/alert", From 173915f956fcb488310df866832ecb0a424ac5fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20P=C3=B5ldaru?= Date: Fri, 23 Dec 2011 18:03:37 +0200 Subject: [PATCH 6/6] Made search function's replace greedy as well. Thanks to gushie the world is better place now :). --- openlp/plugins/remotes/html/openlp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/remotes/html/openlp.js b/openlp/plugins/remotes/html/openlp.js index 5c991a018..56c0c5859 100644 --- a/openlp/plugins/remotes/html/openlp.js +++ b/openlp/plugins/remotes/html/openlp.js @@ -222,7 +222,7 @@ window.OpenLP = { search: function (event) { event.preventDefault(); var text = "{\"request\": {\"text\": \"" + - $("#search-text").val().replace("\\", "\\\\").replace("\"", "\\\"") + + $("#search-text").val().replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + "\"}}"; $.getJSON( "/api/" + $("#search-plugin").val() + "/search",