mirror of
https://github.com/danbulant/node-html-parser
synced 2026-05-19 04:18:52 +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;
|
||||
for (const key in attrs) {
|
||||
const val = attrs[key] || '';
|
||||
this._attrs[key] = decode(val.replace(/^['"]/, '').replace(/['"]$/, ''));
|
||||
this._attrs[key] = decode(val);
|
||||
}
|
||||
return this._attrs;
|
||||
}
|
||||
|
|
@ -477,12 +477,7 @@ export default class HTMLElement extends Node {
|
|||
if (val === undefined || val === null) {
|
||||
return name;
|
||||
} else {
|
||||
return name + '=' + JSON.stringify(val);
|
||||
// if (typeof val === 'string') {
|
||||
// return name + '=' + JSON.stringify(encode(val)); //??? should we encode value here?
|
||||
// } else {
|
||||
// return name + '=' + JSON.stringify(val);
|
||||
// }
|
||||
return name + '=' + JSON.stringify(String(val));
|
||||
}
|
||||
}).join(' ');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -355,7 +355,7 @@ describe('HTML Parser', function () {
|
|||
'b': '13',
|
||||
'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',
|
||||
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>');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue