-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance of unescapeXML #125
Conversation
@@ -49,6 +49,9 @@ vows.describe('escape').addBatch({ | |||
'unescapes \'': function () { | |||
assert.strictEqual(unescapeXML('''), '\'') | |||
}, | |||
'leaves invalid entities alone': function () { | |||
assert.strictEqual(unescapeXML('&foobar;'), '&foobar;') | |||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we throw instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my first inclination, and my first implementation, but I didn't want to break backwards compatibility, so I decided to write a test that verified that the behaviour didn't change. If anything, that might be better to put in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds sane :) good candidate for release 3.0
Invalid entities are passed through silently, meaning that "<a>&foobar;</a>" is allowed, even though it technically isn't valid XML. In order to preserve backwards compatibility, this test has been added to avoid changing this behaviour.
The original replace function uses a regular expression to find expressions to parse. It is more efficient to use the indexOf to find the first matching '&' character and then the matching ';' character. Fixes half of xmppjs#120.
83a52f2
to
8fccfe3
Compare
parsers suite before: Node.js v10.11.0 - Intel(R) Core(TM) i5-2520M CPU @ 2.50GHz |
Half of #120 fixed by this change.