From 0e7a6375e9479ea714e8ea1c30fd97fef3977280 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sun, 7 Feb 2016 14:25:52 -0500 Subject: [PATCH] Escape text, and make spaces display properly. --- js/examples/textfield/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/examples/textfield/index.js b/js/examples/textfield/index.js index 4ee1f4e..ab8991f 100644 --- a/js/examples/textfield/index.js +++ b/js/examples/textfield/index.js @@ -7,11 +7,21 @@ var Patch = Syndicate.Patch; var __ = Syndicate.__; var _$ = Syndicate._$; +function escapeText(text) { + text = text.replace(/&/g, '&'); + text = text.replace(//g, '>'); + text = text.replace(/ /g, ' '); + return text; +} + function piece(text, pos, lo, hi, cls) { return ""+ ((pos >= lo && pos < hi) - ? text.substring(lo, pos) + "" + text.substring(pos, hi) - : text.substring(lo, hi)) + ? (escapeText(text.substring(lo, pos)) + + "" + + escapeText(text.substring(pos, hi))) + : escapeText(text.substring(lo, hi))) + ""; } @@ -60,7 +70,6 @@ function spawnGui() { }, updateDisplay: function () { - // BUG: escape text! var text = this.field ? this.field.text : ""; var pos = this.field ? this.field.pos : 0; var highlight = this.highlight ? this.highlight.state : false;