Skip to content

Commit

Permalink
Fixed closing tag issues (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
emn178 authored Jul 7, 2024
1 parent 4ee0ed2 commit 18cb361
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function element(matchRoot: boolean): XmlParserNodeWrapper<XmlParserElementNode>
throw new ParsingError('Failed to parse XML', `Closing tag not matching "${closingTag}"`);
}
} else {
match(/^<\/\s*[\w-:.\u00C0-\u00FF]+>/);
match(/^<\/[\w-:.\u00C0-\u00FF]+\s*>/);
}

return {
Expand Down
12 changes: 11 additions & 1 deletion test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('XML Parser', function() {
});

it('should support weird whitespace', function() {
const node = xmlParser('<foo \n\n\nbar\n\n= \nbaz>\n\nhello world</\n\nfoo>');
const node = xmlParser('<foo \n\n\nbar\n\n= \nbaz>\n\nhello world</foo>');
assert.deepEqual(node.root, {
type: 'Element',
name: 'foo',
Expand Down Expand Up @@ -260,6 +260,16 @@ describe('XML Parser', function() {
});
});

it('should support closing tags with tailing whitespaces', function() {
const node = xmlParser('<a></a \n>');
assert.deepEqual(node.root, {
type: 'Element',
name: 'a',
attributes: {},
children: []
});
});

it('should support self-closing tags without attributes', function() {
const node = xmlParser('<a><b>foo</b><b /> <b>bar</b></a>');
assert.deepEqual(node.root, {
Expand Down

0 comments on commit 18cb361

Please sign in to comment.