Skip to content

Commit

Permalink
Fixes #30 - end positions for attribute names include whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
justinwilaby committed Jun 20, 2020
1 parent 13ec382 commit 7201d24
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
Binary file modified lib/sax-wasm.wasm
Binary file not shown.
19 changes: 19 additions & 0 deletions src/js/__test__/attribute.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,25 @@ describe('SaxWasm', () => {
parser.end();
});

it('should recognize boolean attributes', () => {
parser.write(Buffer.from('<button disabled class="primary-btn"></button>'));
deepStrictEqual(_event, SaxEventType.Attribute);
deepStrictEqual(_data.length, 2);
deepStrictEqual(_data[0].name, 'disabled');
deepStrictEqual(_data[0].value, '');
})

it('should not include whitespace in the attribute\'s nameEnd value', () => {
parser.write(Buffer.from(`<?xml version="1.0" encoding="UTF-8"?>
<plugin
version = "1.0.0" >
</plugin>`));
deepStrictEqual(_event, SaxEventType.Attribute);
deepStrictEqual(_data.length, 1);
deepStrictEqual(_data[0].name, 'version');
deepStrictEqual(_data[0].nameEnd.character, 11);
})

it('should recognize attribute names', () => {
parser.write(Buffer.from('<body class="main"></body>'));
deepStrictEqual(_event, SaxEventType.Attribute);
Expand Down
1 change: 0 additions & 1 deletion src/sax/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@ impl SAXParser {
}
if grapheme == "=" {
self.state = State::AttribValue;
self.attribute.name_end = (self.line, self.character - 1);
} else {
if grapheme == ">" {
self.process_attribute();
Expand Down

0 comments on commit 7201d24

Please sign in to comment.