Open varjolintu opened 2 years ago
Same applies to query
. If URL has a query and it is set to empty string using set_query()
, printing the URL still shows ?
at the end of the URL.
There's a difference between set_password(Some(""))
and set_password(None)
, the first has an empty string as password and output of .as_str()
is https://:@example.com/
as you mentioned, the later does not have a password and the output is https://example.com/
.
Check the new tests in this PR https://github.com/servo/rust-url/pull/806
From the URL Standard, in URL serializing:
- If url includes credentials, then:
The first link of the quote leads to:
A URL includes credentials if its username or password is not the empty string.
So I think the set_password(Some(""))
should have the same effect on the URL as set_password(None)
, and we should not leave an empty :@
.
This is consistent with normalization, as seen in test_serialization
and test_url_visualizer
. There are also several examples in urltestdata.json
(search for :@
).
However, the standard also says:
Note that the standard does make the distinction between “null” and “empty-string”. So I think set_query(Some(""))
should keep the trailing ?
.
This is consistent with examples of normalization in urltestdata.json
(search for ?"
).
When setting username/password to empty string value,
:
and@
chars should be removed from the URL when usingto_string()
.Steps to reproduce:
String
URL with username and password:https://username:password@example.com
.Url::parse()
from the String.set_username()
andset_password()
to reset the values as empty strings..as_str()
or.to_string()
for theUrl
shows:https://:@example.com/
.Using version 2.3.1 of the crate.