-
Notifications
You must be signed in to change notification settings - Fork 347
Changing the scheme can break things #61
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
Comments
I’m a bit reluctant, since it’s not obvious what the semantics of changing the scheme like this should be. For the case of |
This same issue affects some of the upcoming HSTS code in servo where a If it's not reasonable to mutate the scheme, does it make more sense to make |
@samfoo |
A simple test case is probably the easiest way to show one of the problems (that the default port doesn't change). This is specifically the problem with the pull request for HSTS. I'm not sure how much other internal state the #[test]
fn test_changing_protocol_should_not_retain_the_old_default_port() {
let mut http_url = Url::parse("http://mozilla.org").unwrap();
http_url.scheme = "https".to_string();
assert!(http_url.port().is_none());
assert_eq!(http_url.port_or_default().unwrap(), 443)
}
|
I’m thinking of refactoring the parser and data structure to fix a bunch of things including this. But in the mean time, you can work around this issue by using |
secure_url.relative_scheme_data_mut()
.map(|scheme_data| {
scheme_data.default_port = Some(443);
}); Is the best I could come up with, since |
Yes, I think this is the best we can do without changing the data structure. There could be a |
This passes in 1.0: let mut url = Url::parse("http://mozilla.org").unwrap();
url.set_scheme("https").unwrap();
assert_eq!(url.port(), None);
assert_eq!(url.port_or_known_default(), Some(443));
url.assert_invariants(); #187 adds it as a test case. |
If you change the scheme from a non-relative one to a relative one without regenerating the scheme data, the Url object stops working properly. For example, parsing
view-source+http://google.com
and then usingslice()
onurl.scheme
to make it http again does not change the corresponding scheme data.Perhaps there should be a
set_scheme()
method for setting the scheme safely?The text was updated successfully, but these errors were encountered: