fix: SvelteURL search setter uses unnormalized value (#17828)

## Summary

- The `SvelteURL` `search` setter stored the raw input `value` instead
of `super.search`, unlike every other setter in the class
- This caused `url.search` to return incorrect values when the URL API
normalizes the input (e.g. adding the `?` prefix, or stripping a lone
`?`)
- For example: `url.search = 'foo=bar'` would return `'foo=bar'` instead
of `'?foo=bar'`

## Test plan

- [x] Added `url.search normalizes value` test covering:
  - Setting search without `?` prefix
  - Setting search with `?` prefix (existing behavior)
  - Setting search to lone `?` (normalized to `""`)
- [x] All existing reactivity tests pass (46/46)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
pull/17812/head
Mathias Picker 4 days ago committed by GitHub
parent 6e9b2a6fd8
commit 361b32c7cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: SvelteURL `search` setter now returns the normalized value, matching native URL behavior

@ -171,7 +171,7 @@ export class SvelteURL extends URL {
set search(value) {
super.search = value;
set(this.#search, value);
set(this.#search, super.search);
this.#searchParams[REPLACE](super.searchParams);
}

@ -115,6 +115,35 @@ test('url.searchParams', () => {
cleanup();
});
test('url.search normalizes value', () => {
const url = new SvelteURL('https://svelte.dev');
const log: any = [];
const cleanup = effect_root(() => {
render_effect(() => {
log.push(url.search);
});
});
flushSync(() => {
// setting without ? prefix — URL normalizes to "?foo=bar"
url.search = 'foo=bar';
});
flushSync(() => {
url.search = '?baz=qux';
});
flushSync(() => {
// lone "?" is normalized to ""
url.search = '?';
});
assert.deepEqual(log, ['', '?foo=bar', '?baz=qux', '']);
cleanup();
});
test('SvelteURL instanceof URL', () => {
assert.ok(new SvelteURL('https://svelte.dev') instanceof URL);
});

Loading…
Cancel
Save