Skip to content

Commit 99bae24

Browse files
authored
Merge pull request ashi009#5 from leeoniya/parse-empty-attrs
parse value-less attributes
2 parents 38d7007 + 1917dd7 commit 99bae24

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ 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)) {
466-
attrs[match[1]] = match[3] || match[4] || match[5];
466+
attrs[match[1]] = match[2] || match[3] || match[4] || "";
467467
}
468468
}
469469
this._rawAttrs = attrs;

test/html.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,12 @@ 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\'></p>');
267+
var root = parseHTML('<p a=12 data-id="!$$&amp;" yAz=\'1\' disabled></p>');
268268
root.firstChild.attributes.should.eql({
269269
'a': '12',
270270
'data-id': '!$$&',
271-
'yAz': '1'
271+
'yAz': '1',
272+
'disabled': ''
272273
});
273274
});
274275
});

0 commit comments

Comments
 (0)