@@ -1025,28 +1025,28 @@ impl<'a> Parser<'a> {
1025
1025
input : Input < ' i > ,
1026
1026
) -> Input < ' i > {
1027
1027
let path_start = self . serialization . len ( ) ;
1028
- let ( maybe_c, remaining ) = input. split_first ( ) ;
1028
+ let ( maybe_c, _ ) = input. split_first ( ) ;
1029
1029
// If url is special, then:
1030
1030
if scheme_type. is_special ( ) {
1031
+ // A special URL always has a non-empty path.
1032
+ if maybe_c != Some ( '/' ) {
1033
+ self . serialization . push ( '/' ) ;
1034
+ }
1031
1035
if let Some ( c) = maybe_c {
1032
1036
if c == '\\' {
1033
1037
// If c is U+005C (\), validation error.
1034
1038
self . log_violation ( SyntaxViolation :: Backslash ) ;
1035
1039
}
1036
1040
// Set state to path state.
1037
1041
return self . parse_path ( scheme_type, has_host, path_start, input) ;
1038
- } else {
1039
- // A special URL always has a non-empty path.
1040
- self . serialization . push ( '/' ) ;
1041
1042
}
1042
- } else if maybe_c == Some ( '?' ) {
1043
+ } else if maybe_c == Some ( '?' ) || maybe_c == Some ( '#' ) {
1043
1044
// Otherwise, if state override is not given and c is U+003F (?),
1044
1045
// set url’s query to the empty string and state to query state.
1045
- return self . parse_query_2 ( scheme_type, remaining) ;
1046
- } else if maybe_c == Some ( '#' ) {
1047
1046
// Otherwise, if state override is not given and c is U+0023 (#),
1048
1047
// set url’s fragment to the empty string and state to fragment state.
1049
- return self . parse_fragment_2 ( remaining) ;
1048
+ // The query and path states will be handled by the caller.
1049
+ return input;
1050
1050
}
1051
1051
// Otherwise, if c is not the EOF code point:
1052
1052
self . parse_path ( scheme_type, has_host, path_start, input)
@@ -1166,7 +1166,12 @@ impl<'a> Parser<'a> {
1166
1166
}
1167
1167
}
1168
1168
1169
- match & self . serialization [ segment_start..] {
1169
+ let to_match = if ends_with_slash {
1170
+ & self . serialization [ segment_start..self . serialization . len ( ) - 1 ]
1171
+ } else {
1172
+ & self . serialization [ segment_start..self . serialization . len ( ) ]
1173
+ } ;
1174
+ match to_match {
1170
1175
// If buffer is a double-dot path segment, shorten url’s path,
1171
1176
// 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.
1172
1177
".." | "%2e%2e" | "%2e%2E" | "%2E%2e" | "%2E%2E" | "%2e." | "%2E." | ".%2e"
0 commit comments