Skip to content

Commit

Permalink
fix: handle falsy srcset values (#8901)
Browse files Browse the repository at this point in the history
fixes #8899
  • Loading branch information
dummdidumm authored Jul 3, 2023
1 parent 58e95c6 commit 8de9dc6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-lizards-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: handle falsy srcset values
4 changes: 2 additions & 2 deletions packages/svelte/src/runtime/internal/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
1 change: 1 addition & 0 deletions packages/svelte/test/utils/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
});

0 comments on commit 8de9dc6

Please sign in to comment.