fix the format and use window.location

This commit is contained in:
Yanzhen Yu
2018-12-30 21:50:04 +08:00
parent 91e031844e
commit 7c275cbf2c
2 changed files with 9 additions and 3 deletions

View File

@@ -107,7 +107,7 @@ function serializeNode(n: Node, doc: Document): serializedNode | false {
if (name === 'src' || name === 'href') {
attributes[name] = absoluteToDoc(doc, value);
} else if (name === 'style') {
attributes[name] = absoluteToStylesheet(value, doc.location.href);
attributes[name] = absoluteToStylesheet(value, location.href);
} else {
attributes[name] = value;
}

View File

@@ -48,8 +48,14 @@ describe('absolute url to stylesheet', () => {
});
it('can handle multiple no quote paths', () => {
expect(absoluteToStylesheet('background-image: url(images/b.jpg); background: #aabbcc url(images/a.jpg) 50% 50% repeat;', href)).to.equal(
`background-image: url('http://localhost/css/images/b.jpg'); background: #aabbcc url('http://localhost/css/images/a.jpg') 50% 50% repeat;`,
expect(
absoluteToStylesheet(
'background-image: url(images/b.jpg); background: #aabbcc url(images/a.jpg) 50% 50% repeat;',
href,
),
).to.equal(
`background-image: url('http://localhost/css/images/b.jpg');` +
`background: #aabbcc url('http://localhost/css/images/a.jpg') 50% 50% repeat;`,
);
});