Skip to content

Parser locks up on long input lines #97

Description

@mdierolf

The attached test code fails to parse the attached XML document in a reasonable timeframe:
failing.zip

The issue causing this appears to be a regular expression to split the XML on newlines, which either never returns, or is incredibly slow to return:

At: xmldom/lib/sax.js:69:

function position(p,m){
  while(p>=lineEnd && (m = linePattern.exec(source))){
   lineStart = m.index;
   lineEnd = lineStart + m[0].length;
   locator.lineNumber++;
   //console.log('line++:',locator,startPos,endPos)
  }
  locator.columnNumber = p-lineStart+1;
 }
 var lineStart = 0;
 var lineEnd = 0;
 var linePattern = /.*(?:\r\n?|\n)|.*$/g

It appears that the solution would be to re-engineer the parser to process the XML in stream mode, not by splitting lines with a regular expression

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions