Skip to content
Browse files

Escape special chars when revealing message.

  • Loading branch information...
1 parent cecce3a commit f9a64ffac24eba99f1d247392f1e8378f154ff68 @oakes committed Jun 26, 2012
Showing with 17 additions and 1 deletion.
  1. +17 −1 main.js
View
18 main.js
@@ -122,6 +122,7 @@ var decode = function() {
document.getElementById('choose').style.display = 'none';
document.getElementById('reveal').style.display = 'block';
+ // decrypt if necessary
if (obj.ct) {
try {
obj.text = sjcl.decrypt(password, message);
@@ -130,7 +131,22 @@ var decode = function() {
}
}
- document.getElementById('messageDecoded').innerHTML = obj.text;
+ // escape special characters
+ var escChars = {
+ '&': '&',
+ '<': '&lt;',
+ '>': '&gt;',
+ '"': '&quot;',
+ '\'': '&#39;',
+ '/': '&#x2F;',
+ '\n': '<br/>'
+ };
+ var escHtml = function(string) {
+ return String(string).replace(/[&<>"'\/\n]/g, function (c) {
+ return escChars[c];
+ });
+ };
+ document.getElementById('messageDecoded').innerHTML = escHtml(obj.text);
}
};

0 comments on commit f9a64ff

Please sign in to comment.
Something went wrong with that request. Please try again.