Skip to content

Commit dc2e4ee

Browse files
committed
properly handle attrs with zero length values
1 parent a37b7cc commit dc2e4ee

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export class HTMLElement extends Node {
460460
return this._rawAttrs;
461461
const attrs = {} as RawAttributes;
462462
if (this.rawAttrs) {
463-
const re = /\b([a-z][a-z0-9\-]*)(?:\s*=\s*(?:"([^"]+)"|'([^']+)'|(\S+)))?/ig;
463+
const re = /\b([a-z][a-z0-9\-]*)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/ig;
464464
let match: RegExpExecArray;
465465
while (match = re.exec(this.rawAttrs)) {
466466
attrs[match[1]] = match[2] || match[3] || match[4] || "";

test/html.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,13 @@ describe('HTML Parser', function () {
264264

265265
describe('#attributes', function () {
266266
it('should return attributes of the element', function () {
267-
var root = parseHTML('<p a=12 data-id="!$$&amp;" yAz=\'1\' disabled></p>');
267+
var root = parseHTML('<p a=12 data-id="!$$&amp;" yAz=\'1\' class="" disabled></p>');
268268
root.firstChild.attributes.should.eql({
269269
'a': '12',
270270
'data-id': '!$$&',
271271
'yAz': '1',
272-
'disabled': ''
272+
'disabled': '',
273+
'class': ''
273274
});
274275
});
275276
});

0 commit comments

Comments
 (0)