Strip out slash-escaped JSON sequence received in client.

The server will slash-escape some JSON related characters before sending. Need to strip them out before using, on the client side.
This commit is contained in:
pjhggns 2018-03-02 12:20:08 -08:00 committed by Nanne Baars
parent 5d28ef9fbe
commit 6a5ca43e7e

View File

@ -151,14 +151,23 @@ define(['jquery',
return false; return false;
}, },
removeSlashesFromJSON: function(str) {
// slashes are leftover escapes from JSON serialization by server
// for every two char sequence starting with backslash,
// replace them in the text with second char only
return str.replace(/\\(.)/g, "$1");
},
renderFeedback: function(feedback) { renderFeedback: function(feedback) {
this.$curFeedback.html(polyglot.t(feedback) || ""); var s = this.removeSlashesFromJSON(feedback);
this.$curFeedback.html(polyglot.t(s) || "");
this.$curFeedback.show(400) this.$curFeedback.show(400)
}, },
renderOutput: function(output) { renderOutput: function(output) {
this.$curOutput.html(polyglot.t(output) || ""); var s = this.removeSlashesFromJSON(output);
this.$curOutput.html(polyglot.t(s) || "");
this.$curOutput.show(400) this.$curOutput.show(400)
}, },