fix setAttributes and attributes, also fix some tests, need more fixes

This commit is contained in:
Minas Keshishyan 2020-02-03 13:19:32 +04:00
parent 9e8f0aaf1e
commit 1f0ebc52c7
2 changed files with 4 additions and 9 deletions

View file

@ -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(' ');
}

View file

@ -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="&#x26;&#x26;&#x3C;&#x3E;foo"></p>');
});
});