Skip to content

Commit 5bd674b

Browse files
committed
Add ability to add & < > and any other normal restricted xml character as long as it is inside either a pair of single quotes or double quotes.
1 parent 25852e9 commit 5bd674b

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

js-libs/easysax/easysax.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ EasySAXParser.prototype.parse = function(xml) {
462462
, elem
463463
, tagend = false
464464
, tagstart = false
465-
, j = 0, i = 0
465+
, j = 0, i = 0, k = 0, len
466466
, x, y, q, w
467467
, xmlns
468468
, stopIndex = 0
@@ -472,6 +472,7 @@ EasySAXParser.prototype.parse = function(xml) {
472472
, pos = 0, ln = 0, lnStart = -2, lnEnd = -1
473473
;
474474

475+
len = xml.length;
475476
function getStringNode() {
476477
return xml.substring(i, j+1)
477478
};
@@ -582,7 +583,24 @@ EasySAXParser.prototype.parse = function(xml) {
582583
};
583584
};
584585

585-
j = xml.indexOf('>', i+1);
586+
var inside=false;
587+
for (k=i,j=-1;k<len;k++) {
588+
var c = xml.charCodeAt(k);
589+
if (!inside) {
590+
591+
if (c === 34) { // '"'
592+
inside = c;
593+
}
594+
else if (c === 39) { // "'"
595+
inside = c;
596+
}
597+
else if (c === 62) { // <
598+
j = k; break;
599+
}
600+
} else {
601+
if (c === inside) { inside = false; }
602+
}
603+
}
586604

587605
if (j == -1) { // error
588606
this.onError('...>', position(i + 1));

node-tests/test-xml.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ describe("xml parser", () => {
4343
assert.equal("Ω", last_data);
4444
});
4545

46+
it("resolves <> inside quotes", () => {
47+
parser.parse("<element name='<&>' blah=\"b<a&>\"/>");
48+
assert.equal("<&>", last_attrs.name);
49+
assert.equal("b<a&>", last_attrs.blah);
50+
});
4651
});

0 commit comments

Comments
 (0)