From 8d4a10d9ca86f64c62653af9d541da9506ff58d3 Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Thu, 14 Mar 2013 11:17:27 +0100 Subject: [PATCH 1/2] Fix leak of util variable into global scope. Mocha (http://visionmedia.github.com/mocha/) reports the following error when running tests on code that calls SaxParser().parseString(): Error: global leak detected: util --- lib/node-xml.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node-xml.js b/lib/node-xml.js index 180a482..48d35fe 100755 --- a/lib/node-xml.js +++ b/lib/node-xml.js @@ -480,7 +480,7 @@ XMLP.prototype._parseDTD = function(iB) { } XMLP.prototype._parseElement = function(iB) { - util = require('util'); + var util = require('util'); var iE, iDE, iNE, iRet; var iType, strN, iLast; @@ -805,7 +805,7 @@ SaxParser.prototype.parseFile = function(filename) { //This function will only w SaxParser.prototype.parseString = function(strD) { - util = require('util'); + var util = require('util'); var that = this; var startnew = true; if(!that.m_parser){ From b0911c74e0502a05c74b38f4500b3e2d82fdbace Mon Sep 17 00:00:00 2001 From: Jerome Forissier Date: Thu, 14 Mar 2013 14:37:42 +0100 Subject: [PATCH 2/2] Fix more leaks of variables into global namespace. Fixes the follwing Mocha error: Error: global leaks detected: iRet, theatts, splits, nameobject, that --- lib/node-xml.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node-xml.js b/lib/node-xml.js index 48d35fe..37b4cb8 100755 --- a/lib/node-xml.js +++ b/lib/node-xml.js @@ -273,14 +273,14 @@ XMLP.prototype._parse = function() { ////////// NAMESPACE SUPPORT ////////////////////////////////////////// XMLP.prototype._parsePrefixAndElementName = function (elementlabel){ - splits = elementlabel.split(':',2); + var splits = elementlabel.split(':',2); return { prefix : ((splits.length === 1) ? '' : splits[0]), name : ((splits.length === 1) ? elementlabel : splits[1]), }; } XMLP.prototype._parseNamespacesAndAtts = function (atts){ //translate namespaces into objects with "prefix","uri", "scopetag" Add them to: this.m_namespaceList //The function should return a new list of tag attributes with the namespaces filtered - that = this; + var that = this; var newnamespaces = []; var filteredatts = []; atts.map(function (item){ @@ -339,7 +339,7 @@ XMLP.prototype._removeExpiredNamesapces = function (closingtagname) { XMLP.prototype._parseAttribute = function(iB, iE) { - var iNB, iNE, iEq, iVB, iVE; + var iNB, iNE, iEq, iVB, iVE, iRet; var cQuote, strN, strV; this.m_cAlt = ""; //resets the value so we don't use an old one by accident (see testAttribute7 in the test suite) @@ -634,7 +634,7 @@ XMLP.prototype._replaceEntities = function(strD, iB, iE) { iE = iE || strD.length; - var iEB, iEE, strRet = ""; + var iEB, iEE, strRet = "", iRet; iEB = strD.indexOf("&", iB); iEE = iB; @@ -978,7 +978,7 @@ SaxParser.prototype._fireEvent = function(iEvt) { SaxParser.prototype._parseLoop = function(parser) { - var iEvent, parser; + var iEvent, parser, theattsandnamespace, theatts, nameobject; parser = this.m_parser; while(!this.m_bErr) {