Re: [whatwg/url] Setters can cause failure to roundtrip (#651)

Setters being round-trippable is nice. I'd like to add that I think setters should preserve the structure of the URL component, so that `urlA.component = urlB.component` should strive to not change the component's meaning.

One issue I've been wondering about bringing up is that non-special paths can have unescaped backslashes, but if you go through the setter, the URL parser will then interpret those backslashes as path separators and normalise them to forwardslashes. This violates the `urlA.component = urlB.component` idea if the path is set on a special URL (`urlA` is special, `urlB` is not special). An example from my library:

```swift
// Backslashes are not percent-encoded in non-special URLs,
// so copying the path to a special URL can cause it to be interpreted differently.

var specialURL = WebURL("https://example.com/")!
specialURL.serialized()  // "https://example.com/"
specialURL.path,         // "/"
specialURL.pathComponents.count // 1

let nonSpecialURL = WebURL(#"foo://example.com/baz\qux"#)!
nonSpecialURL.serialized()  // "foo://example.com/baz\qux"
nonSpecialURL.path          // "/baz\qux"
nonSpecialURL.pathComponents.count. // 1

specialURL.path = nonSpecialURL.path

specialURL.serialized()  // "https://example.com/baz/qux" (!)
specialURL.path          // "/baz/qux" (!)
specialURL.pathComponents.count  // 2 (!)
```

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

Received on Monday, 22 November 2021 20:27:58 UTC