Re: [whatwg/url] URLSearchParams inconsistent behavior with multiple same-name parameters leads to data loss on backend (Issue #889)

Voral left a comment (whatwg/url#889)

Although... I started thinking about the problem more deeply and remembered that PHP supports not only simple arrays with `[]`, but also complex nested structures:

```html
<!-- Associative arrays -->
<input name="user[name]">
<input name="user[email]">

<!-- Nested arrays with indexes -->
<input name="items[0][name]">
<input name="items[0][price]">
<input name="items[1][name]">
<input name="items[1][price]">

<!-- And even deep nesting -->
<input name="order[user][contacts][phone]">
```

In PHP, this parses perfectly into full-fledged data structures:
```php
$_POST['user']['name']; // Works
$_POST['items'][0]['name']; // Works
$_POST['order']['user']['contacts']['phone']; // Works
```

And that's when you realize the problem is much deeper than it first appeared. We're talking not just about simple multiple values, but about an entire **mechanism for serializing complex data structures** in URL format.

The current `URLSearchParams` is not designed for such scenarios at all. Yes, I can manually write:
```javascript
params.append('user[name]', 'John');
params.append('user[email]', 'test@example.com');
```

But this:
1. Is **the same workaround**, just for more complex cases
2. Is **inconsistent** - it forces mixing data logic with backend-specific syntactic features
3. Is **hard to scale** for dynamic structures

Perhaps if we're going to add support for PHP notation, we should consider a full-fledged API for working with structures, not just a flag for simple arrays. Although I understand this is much more complex and might be overkill for a native API.

I'm confused :)

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/issues/889#issuecomment-3462100623
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/url/issues/889/3462100623@github.com>

Received on Wednesday, 29 October 2025 15:13:57 UTC