Skip to content

Commit 830c773

Browse files
o0Ignition0onox
authored andcommitted
Fix scheme setter
> test result: FAILED. 650 passed; 63 failed; 0 ignored; 0 measured
1 parent 9ac3f29 commit 830c773

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1922,9 +1922,15 @@ impl Url {
19221922
pub fn set_scheme(&mut self, scheme: &str) -> Result<(), ()> {
19231923
let mut parser = Parser::for_setter(String::new());
19241924
let remaining = parser.parse_scheme(parser::Input::new(scheme))?;
1925-
if !remaining.is_empty()
1926-
|| (!self.has_host() && SchemeType::from(&parser.serialization).is_special())
1927-
{
1925+
let new_scheme_type = SchemeType::from(&parser.serialization);
1926+
let old_scheme_type = SchemeType::from(self.scheme());
1927+
// Switching from special scheme to non special scheme
1928+
// and switching from file to non file is not allowed
1929+
if old_scheme_type != new_scheme_type {
1930+
return Err(());
1931+
}
1932+
1933+
if !remaining.is_empty() || (!self.has_host() && new_scheme_type.is_special()) {
19281934
return Err(());
19291935
}
19301936
let old_scheme_end = self.scheme_end;

src/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl fmt::Display for SyntaxViolation {
138138
}
139139
}
140140

141-
#[derive(Copy, Clone)]
141+
#[derive(Copy, Clone, PartialEq)]
142142
pub enum SchemeType {
143143
File,
144144
SpecialNotFile,

0 commit comments

Comments
 (0)