parse value-less attributes

This commit is contained in:
Leon Sorokin 2019-03-20 02:50:15 -05:00
parent 38d70076fc
commit 1917dd76b5
2 changed files with 5 additions and 4 deletions

View file

@ -460,10 +460,10 @@ export class HTMLElement extends Node {
return this._rawAttrs;
const attrs = {} as RawAttributes;
if (this.rawAttrs) {
const re = /\b([a-z][a-z0-9\-]*)\s*=\s*("([^"]+)"|'([^']+)'|(\S+))/ig;
const re = /\b([a-z][a-z0-9\-]*)(?:\s*=\s*(?:"([^"]+)"|'([^']+)'|(\S+)))?/ig;
let match: RegExpExecArray;
while (match = re.exec(this.rawAttrs)) {
attrs[match[1]] = match[3] || match[4] || match[5];
attrs[match[1]] = match[2] || match[3] || match[4] || "";
}
}
this._rawAttrs = attrs;

View file

@ -264,11 +264,12 @@ describe('HTML Parser', function () {
describe('#attributes', function () {
it('should return attributes of the element', function () {
var root = parseHTML('<p a=12 data-id="!$$&amp;" yAz=\'1\'></p>');
var root = parseHTML('<p a=12 data-id="!$$&amp;" yAz=\'1\' disabled></p>');
root.firstChild.attributes.should.eql({
'a': '12',
'data-id': '!$$&',
'yAz': '1'
'yAz': '1',
'disabled': ''
});
});
});