Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle falsy srcset values #8901

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
});
});
});