|
@@ -45,6 +45,7 @@ pub enum ParseError {
|
|
|
InvalidPercentEncoded,
|
|
InvalidPercentEncoded,
|
|
|
InvalidAtSymbolInUser,
|
|
InvalidAtSymbolInUser,
|
|
|
ExpectedTwoSlashes,
|
|
ExpectedTwoSlashes,
|
|
|
|
|
+ ExpectedInitialSlash,
|
|
|
NonUrlCodePoint,
|
|
NonUrlCodePoint,
|
|
|
RelativeUrlWithScheme,
|
|
RelativeUrlWithScheme,
|
|
|
RelativeUrlWithoutBase,
|
|
RelativeUrlWithoutBase,
|
|
@@ -68,6 +69,7 @@ impl Show for ParseError {
|
|
|
InvalidPercentEncoded => "Invalid percent-encoded sequence",
|
|
InvalidPercentEncoded => "Invalid percent-encoded sequence",
|
|
|
InvalidAtSymbolInUser => "Invalid @-symbol in user",
|
|
InvalidAtSymbolInUser => "Invalid @-symbol in user",
|
|
|
ExpectedTwoSlashes => "Expected two slashes (//)",
|
|
ExpectedTwoSlashes => "Expected two slashes (//)",
|
|
|
|
|
+ ExpectedInitialSlash => "Expected the input to start with a slash",
|
|
|
NonUrlCodePoint => "Non URL code point",
|
|
NonUrlCodePoint => "Non URL code point",
|
|
|
RelativeUrlWithScheme => "Relative URL with scheme",
|
|
RelativeUrlWithScheme => "Relative URL with scheme",
|
|
|
RelativeUrlWithoutBase => "Relative URL without a base",
|
|
RelativeUrlWithoutBase => "Relative URL without a base",
|
|
@@ -472,6 +474,22 @@ fn parse_file_host<'a>(input: &'a str, parser: &UrlParser) -> ParseResult<(Host,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+pub fn parse_standalone_path(input: &str, parser: &UrlParser)
|
|
|
|
|
+ -> ParseResult<(Vec<String>, Option<String>, Option<String>)> {
|
|
|
|
|
+ if !input.starts_with("/") {
|
|
|
|
|
+ if input.starts_with("\\") {
|
|
|
|
|
+ try!(parser.parse_error(InvalidBackslash));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return Err(ExpectedInitialSlash)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let (path, remaining) = try!(parse_path(
|
|
|
|
|
+ [], input.slice_from(1), UrlParserContext, RelativeScheme(0), parser));
|
|
|
|
|
+ let (query, fragment) = try!(parse_query_and_fragment(remaining, parser));
|
|
|
|
|
+ Ok((path, query, fragment))
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
pub fn parse_path_start<'a>(input: &'a str, context: Context, scheme_type: SchemeType,
|
|
pub fn parse_path_start<'a>(input: &'a str, context: Context, scheme_type: SchemeType,
|
|
|
parser: &UrlParser)
|
|
parser: &UrlParser)
|
|
|
-> ParseResult<(Vec<String>, &'a str)> {
|
|
-> ParseResult<(Vec<String>, &'a str)> {
|