mirror of
https://github.com/danbulant/node-html-parser
synced 2026-06-19 14:41:10 +00:00
fix setAttributes and attributes, also fix some tests, need more fixes
This commit is contained in:
parent
9e8f0aaf1e
commit
1f0ebc52c7
2 changed files with 4 additions and 9 deletions
|
|
@ -407,7 +407,7 @@ export default class HTMLElement extends Node {
|
||||||
const attrs = this.rawAttributes;
|
const attrs = this.rawAttributes;
|
||||||
for (const key in attrs) {
|
for (const key in attrs) {
|
||||||
const val = attrs[key] || '';
|
const val = attrs[key] || '';
|
||||||
this._attrs[key] = decode(val.replace(/^['"]/, '').replace(/['"]$/, ''));
|
this._attrs[key] = decode(val);
|
||||||
}
|
}
|
||||||
return this._attrs;
|
return this._attrs;
|
||||||
}
|
}
|
||||||
|
|
@ -477,12 +477,7 @@ export default class HTMLElement extends Node {
|
||||||
if (val === undefined || val === null) {
|
if (val === undefined || val === null) {
|
||||||
return name;
|
return name;
|
||||||
} else {
|
} else {
|
||||||
return name + '=' + JSON.stringify(val);
|
return name + '=' + JSON.stringify(String(val));
|
||||||
// if (typeof val === 'string') {
|
|
||||||
// return name + '=' + JSON.stringify(encode(val)); //??? should we encode value here?
|
|
||||||
// } else {
|
|
||||||
// return name + '=' + JSON.stringify(val);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}).join(' ');
|
}).join(' ');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -355,7 +355,7 @@ describe('HTML Parser', function () {
|
||||||
'b': '13',
|
'b': '13',
|
||||||
'c': '2'
|
'c': '2'
|
||||||
});
|
});
|
||||||
root.firstChild.toString().should.eql('<p a="12" b=13 c="2"></p>');
|
root.firstChild.toString().should.eql('<p a="12" b="13" c="2"></p>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -370,7 +370,7 @@ describe('HTML Parser', function () {
|
||||||
'c': '12',
|
'c': '12',
|
||||||
d: '&&<>foo'
|
d: '&&<>foo'
|
||||||
});
|
});
|
||||||
root.firstChild.toString().should.eql('<p c=12 d="&&<>foo"></p>');
|
root.firstChild.toString().should.eql('<p c="12" d="&&<>foo"></p>');
|
||||||
// root.firstChild.toString().should.eql('<p c=12 d="&&<>foo"></p>');
|
// root.firstChild.toString().should.eql('<p c=12 d="&&<>foo"></p>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue