fix: handle falsy srcset values (#8901)

fixes #8899
pull/8902/head
Simon H 2 years ago committed by GitHub
parent 58e95c6aca
commit 8de9dc6144
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: handle falsy srcset values

@ -90,12 +90,12 @@ function split_srcset(srcset) {
/**
* @param {HTMLSourceElement | HTMLImageElement} element_srcset
* @param {string} srcset
* @param {string | undefined | null} srcset
* @returns {boolean}
*/
export function srcset_url_equal(element_srcset, srcset) {
const element_urls = split_srcset(element_srcset.srcset);
const urls = split_srcset(srcset);
const urls = split_srcset(srcset || '');
return (
urls.length === element_urls.length &&

@ -162,6 +162,7 @@ describe('utils', () => {
it('should return false if urls are different', () => {
assert.notOk(srcset_url_equal(create_element('a 1x'), 'b 1x'));
assert.notOk(srcset_url_equal(create_element('a 2x'), 'a 1x'));
assert.notOk(srcset_url_equal(create_element('a 2x'), null));
});
});
});

Loading…
Cancel
Save