mirror of
https://github.com/danbulant/node-html-parser
synced 2026-05-19 04:18:52 +00:00
Merge pull request #7 from leeoniya/parse-empty-attrs
properly handle attrs with zero length values
This commit is contained in:
commit
d464145bc2
2 changed files with 4 additions and 3 deletions
|
|
@ -460,7 +460,7 @@ 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[2] || match[3] || match[4] || "";
|
||||
|
|
|
|||
|
|
@ -264,12 +264,13 @@ 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\' disabled></p>');
|
||||
var root = parseHTML('<p a=12 data-id="!$$&" yAz=\'1\' class="" disabled></p>');
|
||||
root.firstChild.attributes.should.eql({
|
||||
'a': '12',
|
||||
'data-id': '!$$&',
|
||||
'yAz': '1',
|
||||
'disabled': ''
|
||||
'disabled': '',
|
||||
'class': ''
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue