@@ -99,14 +99,13 @@ pub fn host(url: &Url) -> &str {
99
99
100
100
/// Setter for https://url.spec.whatwg.org/#dom-url-host
101
101
pub fn set_host ( url : & mut Url , new_host : & str ) -> Result < ( ) , ( ) > {
102
+ // If context object’s url’s cannot-be-a-base-URL flag is set, then return.
103
+ if url. cannot_be_a_base ( ) {
104
+ return Err ( ( ) ) ;
105
+ }
102
106
let host;
103
107
let opt_port;
104
108
{
105
- // If context object’s url’s cannot-be-a-base-URL flag is set, then return.
106
- if url. cannot_be_a_base ( ) {
107
- return Err ( ( ) ) ;
108
- }
109
-
110
109
let scheme = url. scheme ( ) ;
111
110
let result = Parser :: parse_host ( Input :: new ( new_host) , SchemeType :: from ( scheme) ) ;
112
111
match result {
@@ -202,18 +201,19 @@ pub fn pathname(url: &Url) -> &str {
202
201
203
202
/// Setter for https://url.spec.whatwg.org/#dom-url-pathname
204
203
pub fn set_pathname ( url : & mut Url , new_pathname : & str ) {
205
- if !url. cannot_be_a_base ( ) && !new_pathname. is_empty ( ) {
206
- if !SchemeType :: from ( url. scheme ( ) ) . is_special ( )
204
+ if !url. cannot_be_a_base ( ) {
205
+ return ;
206
+ }
207
+ if !SchemeType :: from ( url. scheme ( ) ) . is_special ( )
207
208
|| Some ( '/' ) == new_pathname. chars ( ) . nth ( 0 )
208
209
// \\ is a segment delimiter for 'special' URLs"
209
210
|| Some ( '\\' ) == new_pathname. chars ( ) . nth ( 0 )
210
- {
211
- url. set_path ( new_pathname)
212
- } else {
213
- let mut path_to_set = String :: from ( "/" ) ;
214
- path_to_set. push_str ( new_pathname) ;
215
- url. set_path ( & path_to_set)
216
- }
211
+ {
212
+ url. set_path ( new_pathname)
213
+ } else {
214
+ let mut path_to_set = String :: from ( "/" ) ;
215
+ path_to_set. push_str ( new_pathname) ;
216
+ url. set_path ( & path_to_set)
217
217
}
218
218
}
219
219
0 commit comments