[Pkg-javascript-commits] [node-htmlescape] 04/12: Add sanitize export

Bastien Roucariès rouca at moszumanska.debian.org
Sun Aug 20 13:48:42 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-htmlescape.

commit 3e6cf0614dd0f778fd0131e69070b77282150c15
Author: Andres Suarez <zertosh at gmail.com>
Date:   Sun Apr 12 17:52:46 2015 -0400

    Add sanitize export
---
 htmlescape.js           | 17 +++++++++++++++++
 test/htmlescape-test.js | 14 ++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/htmlescape.js b/htmlescape.js
index 62119b4..5f0ce6c 100644
--- a/htmlescape.js
+++ b/htmlescape.js
@@ -23,3 +23,20 @@ function escaper(match) {
 module.exports = function(obj) {
   return JSON.stringify(obj).replace(ESCAPE_REGEX, escaper);
 };
+
+/***/
+
+var TERMINATORS_LOOKUP = {
+  '\u2028': '\\u2028',
+  '\u2029': '\\u2029'
+};
+
+var TERMINATORS_REGEX = /[\u2028\u2029]/g;
+
+function sanitizer(match) {
+  return TERMINATORS_LOOKUP[match];
+}
+
+module.exports.sanitize = function(str) {
+  return str.replace(TERMINATORS_REGEX, sanitizer);
+};
diff --git a/test/htmlescape-test.js b/test/htmlescape-test.js
index ceb5906..d83fc9d 100644
--- a/test/htmlescape-test.js
+++ b/test/htmlescape-test.js
@@ -57,4 +57,18 @@ test('htmlescape', function(t) {
     t.end();
   });
 
+  t.test('sanitized terminators should work', function(t) {
+    t.doesNotThrow(function() {
+      vm.runInNewContext(htmlescape.sanitize('("\u2028\u2029")'));
+    });
+    t.end();
+  });
+
+  t.test('unsanitized terminators should not work', function(t) {
+    t.throws(function() {
+      vm.runInNewContext('("\u2028\u2029")');
+    });
+    t.end();
+  });
+
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-htmlescape.git



More information about the Pkg-javascript-commits mailing list