File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -1978,9 +1978,15 @@ impl Url {
1978
1978
pub fn set_scheme ( & mut self , scheme : & str ) -> Result < ( ) , ( ) > {
1979
1979
let mut parser = Parser :: for_setter ( String :: new ( ) ) ;
1980
1980
let remaining = parser. parse_scheme ( parser:: Input :: new ( scheme) ) ?;
1981
- if !remaining. is_empty ( )
1982
- || ( !self . has_host ( ) && SchemeType :: from ( & parser. serialization ) . is_special ( ) )
1983
- {
1981
+ let new_scheme_type = SchemeType :: from ( & parser. serialization ) ;
1982
+ let old_scheme_type = SchemeType :: from ( self . scheme ( ) ) ;
1983
+ // Switching from special scheme to non special scheme
1984
+ // and switching from file to non file is not allowed
1985
+ if old_scheme_type != new_scheme_type {
1986
+ return Err ( ( ) ) ;
1987
+ }
1988
+
1989
+ if !remaining. is_empty ( ) || ( !self . has_host ( ) && new_scheme_type. is_special ( ) ) {
1984
1990
return Err ( ( ) ) ;
1985
1991
}
1986
1992
let old_scheme_end = self . scheme_end ;
@@ -2004,6 +2010,13 @@ impl Url {
2004
2010
2005
2011
parser. serialization . push_str ( self . slice ( old_scheme_end..) ) ;
2006
2012
self . serialization = parser. serialization ;
2013
+
2014
+ // Update the port so it can be removed
2015
+ // If it is the scheme's default
2016
+ // We don't mind it silently failing
2017
+ // If there was no port in the first place
2018
+ let _ = self . set_port ( self . port ( ) ) ;
2019
+
2007
2020
Ok ( ( ) )
2008
2021
}
2009
2022
Original file line number Diff line number Diff line change @@ -156,7 +156,7 @@ impl fmt::Display for SyntaxViolation {
156
156
}
157
157
}
158
158
159
- #[ derive( Copy , Clone ) ]
159
+ #[ derive( Copy , Clone , PartialEq ) ]
160
160
pub enum SchemeType {
161
161
File ,
162
162
SpecialNotFile ,
You can’t perform that action at this time.
0 commit comments