Skip to content

Commit

Permalink
Fix catastrophic backtracking with reference RegExp. Fixes issue #9.
Browse files Browse the repository at this point in the history
  • Loading branch information
rossj committed Apr 20, 2020
1 parent c4c201a commit bdbeaba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ exports.Name = regex`
// Loose implementation. The entity will be validated in the `replaceReference`
// function.
exports.Reference = regex`
&\S+?;
&[^\s&]+?;
`;

exports.S = regex`
Expand Down
11 changes: 11 additions & 0 deletions tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,17 @@ describe("parseXml()", () => {
assert.equal(root.attributes.c, " a z ");
assert.equal(root.attributes.d, " a z ");
});

it("should handle many character references in a single attribute", () => {
{
let [ root ] = parseXml('<a b="&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;"/>').children;
assert.equal(root.attributes.b, "<".repeat(35));
}
{
let [ root ] = parseXml('<a b="&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;"></a>').children;
assert.equal(root.attributes.b, "<".repeat(35));
}
});
});
});

Expand Down

0 comments on commit bdbeaba

Please sign in to comment.