[Pkg-javascript-commits] [ltx] 431/469: use escapeXML from escape.js

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:03:35 UTC 2016


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

js pushed a commit to branch master
in repository ltx.

commit 5b7e02a0a091cf7e6fdf86b49a0e4f0ff7549870
Author: Sonny Piers <sonny at fastmail.net>
Date:   Fri Feb 26 13:56:46 2016 +0100

    use escapeXML from escape.js
---
 lib/parsers/ltx.js      | 15 +++------------
 lib/parsers/node-xml.js | 14 +++-----------
 2 files changed, 6 insertions(+), 23 deletions(-)

diff --git a/lib/parsers/ltx.js b/lib/parsers/ltx.js
index c0b891a..4ba23d2 100644
--- a/lib/parsers/ltx.js
+++ b/lib/parsers/ltx.js
@@ -2,6 +2,7 @@
 
 var inherits = require('inherits')
 var EventEmitter = require('events').EventEmitter
+var unescapeXML = require('../escape').unescapeXML
 
 var STATE_TEXT = 0
 var STATE_IGNORE_TAG = 1
@@ -65,7 +66,7 @@ var SaxLtx = module.exports = function SaxLtx () {
           if (c === 60 /* < */) {
             var text = endRecording()
             if (text) {
-              this.emit('text', unescapeXml(text))
+              this.emit('text', unescapeXML(text))
             }
             state = STATE_TAG_NAME
             recordStart = pos + 1
@@ -127,7 +128,7 @@ var SaxLtx = module.exports = function SaxLtx () {
           break
         case STATE_ATTR_VALUE:
           if (c === attrQuote) {
-            var value = unescapeXml(endRecording())
+            var value = unescapeXML(endRecording())
             attrs[attrName] = value
             attrName = undefined
             state = STATE_TAG
@@ -160,13 +161,3 @@ SaxLtx.prototype.end = function (data) {
   /* Uh, yeah */
   this.write = function () {}
 }
-
-function unescapeXml (s) {
-  return s
-    .replace(/\&(amp|#38);/g, '&')
-    .replace(/\&(lt|#60);/g, '<')
-    .replace(/\&(gt|#62);/g, '>')
-    .replace(/\&(quot|#34);/g, '"')
-    .replace(/\&(apos|#39);/g, "'")
-    .replace(/\&(nbsp|#160);/g, '\n')
-}
diff --git a/lib/parsers/node-xml.js b/lib/parsers/node-xml.js
index 277eb10..9fef12e 100644
--- a/lib/parsers/node-xml.js
+++ b/lib/parsers/node-xml.js
@@ -3,6 +3,7 @@
 var inherits = require('inherits')
 var EventEmitter = require('events').EventEmitter
 var xml = require('node-xml')
+var unescapeXML = require('../escape').unescapeXML
 
 /**
  * This cannot be used as long as node-xml starts parsing only after
@@ -20,12 +21,12 @@ var SaxNodeXML = module.exports = function SaxNodeXML () {
       }
       for (i = 0; i < attrs.length; i++) {
         var attr = attrs[i]
-        attrsHash[attr[0]] = unescapeXml(attr[1])
+        attrsHash[attr[0]] = unescapeXML(attr[1])
       }
       for (i = 0; i < namespaces.length; i++) {
         var namespace = namespaces[i]
         var k = !namespace[0] ? 'xmlns' : 'xmlns:' + namespace[0]
-        attrsHash[k] = unescapeXml(namespace[1])
+        attrsHash[k] = unescapeXML(namespace[1])
       }
       self.emit('startElement', elem, attrsHash)
     })
@@ -59,12 +60,3 @@ SaxNodeXML.prototype.end = function (data) {
     this.write(data)
   }
 }
-
-function unescapeXml (s) {
-  return s
-    .replace(/\&/g, '&')
-    .replace(/\</g, '<')
-    .replace(/\>/g, '>')
-    .replace(/\"/g, '"')
-    .replace(/\'/g, "'")
-}

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



More information about the Pkg-javascript-commits mailing list