mirror of
https://github.com/danbulant/node-html-parser
synced 2026-05-19 12:29:07 +00:00
parse value-less attributes
This commit is contained in:
parent
38d70076fc
commit
1917dd76b5
2 changed files with 5 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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="!$$&" yAz=\'1\'></p>');
|
||||
var root = parseHTML('<p a=12 data-id="!$$&" yAz=\'1\' disabled></p>');
|
||||
root.firstChild.attributes.should.eql({
|
||||
'a': '12',
|
||||
'data-id': '!$$&',
|
||||
'yAz': '1'
|
||||
'yAz': '1',
|
||||
'disabled': ''
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue