Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

escape linefeeds in json string to prevent parser exceptions #1002

Merged
merged 1 commit into from Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion client/source/class/cv/io/parser/Json.js
@@ -1,5 +1,5 @@
/**
* Sometimes the openHAB1 backend returns invalid JSON (e.g. multiple JSON object in one string)
* Sometimes the backend returns invalid JSON (e.g. multiple JSON object in one string) or there are linefeeds in the values.
* This parser can handle those strings
*/
qx.Class.define('cv.io.parser.Json', {
Expand All @@ -15,6 +15,7 @@ qx.Class.define('cv.io.parser.Json', {
"jquery": function(data) {
var result = {};
try {
data = data.replace(/\n/g, "\\n");
result = JSON.parse(data);
} catch (e) {
data.split("}{").forEach(function(subData, i) {
Expand All @@ -31,6 +32,7 @@ qx.Class.define('cv.io.parser.Json', {
"qx": function(data) {
var result = {};
try {
data = data.replace(/\n/g, "\\n");
result = qx.lang.Json.parse(data);
} catch (e) {
data.split("}{").forEach(function(subData, i) {
Expand Down
2 changes: 1 addition & 1 deletion client/source/class/cv/io/transport/Sse.js
Expand Up @@ -98,7 +98,7 @@ qx.Class.define('cv.io.transport.Sse', {
*/
handleMessage: function (e) {
this.client.record("read", e.data);
var json = JSON.parse(e.data);
var json = cv.io.parser.Json.parse(e.data);
var data = json.d;
this.client.update(data);
this.client.setDataReceived(true);
Expand Down