@@ -1043,28 +1043,28 @@ impl<'a> Parser<'a> {
1043
1043
input : Input < ' i > ,
1044
1044
) -> Input < ' i > {
1045
1045
let path_start = self . serialization . len ( ) ;
1046
- let ( maybe_c, remaining ) = input. split_first ( ) ;
1046
+ let ( maybe_c, _ ) = input. split_first ( ) ;
1047
1047
// If url is special, then:
1048
1048
if scheme_type. is_special ( ) {
1049
+ // A special URL always has a non-empty path.
1050
+ if maybe_c != Some ( '/' ) {
1051
+ self . serialization . push ( '/' ) ;
1052
+ }
1049
1053
if let Some ( c) = maybe_c {
1050
1054
if c == '\\' {
1051
1055
// If c is U+005C (\), validation error.
1052
1056
self . log_violation ( SyntaxViolation :: Backslash ) ;
1053
1057
}
1054
1058
// Set state to path state.
1055
1059
return self . parse_path ( scheme_type, has_host, path_start, input) ;
1056
- } else {
1057
- // A special URL always has a non-empty path.
1058
- self . serialization . push ( '/' ) ;
1059
1060
}
1060
- } else if maybe_c == Some ( '?' ) {
1061
+ } else if maybe_c == Some ( '?' ) || maybe_c == Some ( '#' ) {
1061
1062
// Otherwise, if state override is not given and c is U+003F (?),
1062
1063
// set url’s query to the empty string and state to query state.
1063
- return self . parse_query_2 ( scheme_type, remaining) ;
1064
- } else if maybe_c == Some ( '#' ) {
1065
1064
// Otherwise, if state override is not given and c is U+0023 (#),
1066
1065
// set url’s fragment to the empty string and state to fragment state.
1067
- return self . parse_fragment_2 ( remaining) ;
1066
+ // The query and path states will be handled by the caller.
1067
+ return input;
1068
1068
}
1069
1069
// Otherwise, if c is not the EOF code point:
1070
1070
self . parse_path ( scheme_type, has_host, path_start, input)
@@ -1184,7 +1184,12 @@ impl<'a> Parser<'a> {
1184
1184
}
1185
1185
}
1186
1186
1187
- match & self . serialization [ segment_start..] {
1187
+ let to_match = if ends_with_slash {
1188
+ & self . serialization [ segment_start..self . serialization . len ( ) - 1 ]
1189
+ } else {
1190
+ & self . serialization [ segment_start..self . serialization . len ( ) ]
1191
+ } ;
1192
+ match to_match {
1188
1193
// If buffer is a double-dot path segment, shorten url’s path,
1189
1194
// and then if neither c is U+002F (/), nor url is special and c is U+005C (\), append the empty string to url’s path.
1190
1195
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
0 commit comments