Skip to content

Commit

Permalink
fix: fix corrupted attribute values when there is no text handler
Browse files Browse the repository at this point in the history
Closes #38
  • Loading branch information
lddubeau committed Apr 10, 2020
1 parent 0b32132 commit e135f11
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/saxes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1526,15 +1526,22 @@ export class SaxesParser<O extends SaxesOptions = {}> {
start = this.i;
break;
case SEMICOLON: {
const { entityReturnState } = this;
const entity = this.entity + chunk.slice(start, this.prevI);
this.state = this.entityReturnState!;
this.state = entityReturnState!;
let parsed: string;
if (entity === "") {
this.fail("empty entity name.");
this.text += "&;";
return;
parsed = "&;";
}
else {
parsed = this.parseEntity(entity);
this.entity = "";
}

if (entityReturnState !== S_TEXT || this.textHandler !== undefined) {
this.text += parsed;
}
this.text += this.parseEntity(entity);
this.entity = "";
// eslint-disable-next-line no-labels
break loop;
}
Expand Down
19 changes: 19 additions & 0 deletions test/issue-38.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { test } from "./testutil";

test({
name: "issue 38",
xml: `\
<?xml version="1.0" encoding="UTF-8"?>
<top>
<x>Fnord '&lt;' and then some.</x>
<x x="foo"></x>
</top>
`,
expect: [
["opentag", { name: "top", attributes: {}, isSelfClosing: false }],
["opentag", { name: "x", attributes: {}, isSelfClosing: false }],
["opentag", { name: "x", attributes: { x: "foo" }, isSelfClosing: false }],
],
opt: {},
events: ["opentag"],
});

0 comments on commit e135f11

Please sign in to comment.