Permalink
Browse files

Fixed a problem with substring. Calling it on an object rather than a…

… string. Call toString to make sure it's a string.

Signed-off-by: Nick Campbell <nicholas.j.campbell@gmail.com>
  • Loading branch information...
1 parent 14a133f commit 6d102a5b437a985ae6ac003d1afecca7b3d4b439 @ncb000gt ncb000gt committed with robrighter Apr 26, 2010
Showing with 34 additions and 34 deletions.
  1. +34 −34 lib/node-xml.js
View
@@ -2,9 +2,9 @@
// An xml parser for node.js
// (C) Rob Righter (@robrighter) 2009 - 2010, Licensed under the MIT-LICENSE
// Contributions from David Joham
-
-(function () {
+
+(function () {
// CONSTANTS
var whitespace = "\n\r\t ";
@@ -86,7 +86,7 @@ XMLP._errs[XMLP.ERR_ELM_NESTING = 17] = "Element: must be nested correctly";
XMLP.prototype.continueParsing = function(strXML) {
-
+
if(this.m_chunkTransitionContinuation){
strXML = this.m_chunkTransitionContinuation + strXML;
}
@@ -153,7 +153,7 @@ XMLP.prototype._checkStructure = function(iEvent) {
return iEvent;
-}
+}
XMLP.prototype._clearAttributes = function() {
this.m_atts = new Array();
@@ -255,7 +255,7 @@ XMLP.prototype._parse = function() {
else{
return this._parseText (this.m_iP);
}
-
+
}
@@ -297,15 +297,15 @@ XMLP.prototype._getContextualNamespace = function (prefix){
}
}
}
-
+
//no match was found for the prefix so pop off the first non-prefix namespace
for(var i = (this.m_namespaceList.length-1); i>= 0; i--){
var item = this.m_namespaceList[i];
if(item.prefix === ''){
return item.uri;
}
}
-
+
//still nothing, lets just return an empty string
return '';
}
@@ -318,9 +318,9 @@ XMLP.prototype._removeExpiredNamesapces = function (closingtagname) {
keeps.push(item);
}
});
-
+
this.m_namespaceList = keeps;
-
+
}
////////////////////////////////////////////////////////////////////////
@@ -331,7 +331,7 @@ XMLP.prototype._parseAttribute = function(iB, iE) {
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)
-
+
iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
if((iNB == -1) ||(iNB >= iE)) {
return iNB;
@@ -671,16 +671,16 @@ XMLP.prototype._replaceEntity = function(strD, iB, iE) {
case "apos": strEnt = "'"; break;
case "quot": strEnt = "\""; break;
case "nbsp":strEnt = ''; break;
- case "lt":strEnt = '<'; break;
- case "gt":strEnt = '>'; break;
- case "amp":strEnt = '&'; break;
+ case "lt":strEnt = '<'; break;
+ case "gt":strEnt = '>'; break;
+ case "amp":strEnt = '&'; break;
case "cent":strEnt = "¢"; break;
case "pound":strEnt = '£'; break;
case "yen":strEnt = '¥'; break;
- case "euro":strEnt = ''; break;
- case "sect":strEnt = '§'; break;
- case "copy":strEnt = '©'; break;
- case "reg":strEnt = '®'; break;
+ case "euro":strEnt = ''; break;
+ case "sect":strEnt = '§'; break;
+ case "copy":strEnt = '©'; break;
+ case "reg":strEnt = '®'; break;
default:
if(strD.charAt(iB) == "#") {
strEnt = String.fromCharCode(parseInt(strD.substring(iB + 1, iE)));
@@ -693,7 +693,7 @@ XMLP.prototype._replaceEntity = function(strD, iB, iE) {
this._setContent(XMLP._CONT_ALT, strEnt);
return XMLP._ENTITY;
-}
+}
XMLP.prototype._setContent = function(iSrc) {
var args = arguments;
@@ -709,7 +709,7 @@ XMLP.prototype._setContent = function(iSrc) {
}
this.m_cSrc = iSrc;
-}
+}
XMLP.prototype._setErr = function(iErr) {
var strErr = XMLP._errs[iErr];
@@ -728,11 +728,11 @@ XMLP.prototype._setErr = function(iErr) {
//event-based interface for parsing. This is the object users interact with when coding
//with XML for <SCRIPT>
var SaxParser = function(eventhandlerfactory) {
-
+
var eventhandler = new function(){
-
+
}
-
+
var thehandler = function() {};
thehandler.prototype.onStartDocument = function (funct){
eventhandler.onStartDocument = funct;
@@ -758,12 +758,12 @@ var SaxParser = function(eventhandlerfactory) {
thehandler.prototype.onWarning = function(funct) {
eventhandler.onWarning = funct;
}
-
+
thehandler.prototype.onError = function(funct) {
eventhandler.onError = funct;
}
-
-
+
+
eventhandlerfactory(new thehandler());
//eventhandler = eventhandler(eventhandler);
this.m_hndDoc = eventhandler;
@@ -809,11 +809,11 @@ SaxParser.prototype.parseString = function(strD) {
that.m_parser.continueParsing(strD);
startnew = true;
}
-
+
//if(that.m_hndDoc && that.m_hndDoc.setDocumentLocator) {
// that.m_hndDoc.setDocumentLocator(that);
//}
-
+
that.m_bErr = false;
if(!that.m_bErr && !startnew) {
@@ -906,8 +906,8 @@ SaxParser.prototype._fireError = function(strMsg) {
SaxParser.prototype._fireEvent = function(iEvt) {
var hnd, func, args = arguments, iLen = args.length - 1;
-
-
+
+
if(this.m_bErr) return;
if(SaxParser.DOC_B == iEvt) {
@@ -937,7 +937,7 @@ SaxParser.prototype._fireEvent = function(iEvt) {
else if (SaxParser.CMNT == iEvt) {
func = "onComment"; hnd = this.m_hndLex;
}
-
+
if(hnd && hnd[func]) {
if(0 == iLen) {
hnd[func]();
@@ -970,7 +970,7 @@ SaxParser.prototype._parseLoop = function(parser) {
parser = this.m_parser;
while(!this.m_bErr) {
iEvent = parser.next();
-
+
if(iEvent == XMLP._ELM_B) {
theatts = this.m_parser.m_atts;
nameobject = parser._parsePrefixAndElementName(parser.getName());
@@ -991,7 +991,7 @@ SaxParser.prototype._parseLoop = function(parser) {
theattsandnamespace = parser._parseNamespacesAndAtts(theatts);
var theuri = parser._getContextualNamespace(nameobject.prefix);
this._fireEvent(SaxParser.ELM_B, nameobject.name, theattsandnamespace[0], (nameobject.prefix === '')? null : nameobject.prefix, (theuri === '')? null : theuri ,theattsandnamespace[1] );
-
+
parser._removeExpiredNamesapces(parser.getName());
this._fireEvent(SaxParser.ELM_E, nameobject.name, (nameobject.prefix === '')? null : nameobject.prefix, (theuri === '')? null : theuri);
//this._fireEvent(SaxParser.ELM_B, parser.getName(), this.m_parser.m_atts.map(function(item){return { name : item[0], value : item[1], };}) );
@@ -1028,7 +1028,7 @@ SaxParser.prototype._parseLoop = function(parser) {
}
}
-}
+}
//SAXStrings: a useful object containing string manipulation functions
var SAXStrings = function() {
@@ -1121,7 +1121,7 @@ SAXStrings.replace = function(strD, iB, iE, strF, strR) {
iB = iB || 0;
iE = iE || strD.length;
- return strD.substring(iB, iE).split(strF).join(strR);
+ return strD.toString().substring(iB, iE).split(strF).join(strR);
}

0 comments on commit 6d102a5

Please sign in to comment.