From 25ce03b6102cf017cf9cbba7e28dbd0d76ab5a5d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 1 Aug 2020 01:19:16 +0200 Subject: SuggestionUrl: Return an error if path has less than two segments We need two segments in the path to parse the owner-repo combination. --- src/url.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/url.rs') diff --git a/src/url.rs b/src/url.rs index d635d6f..60a3d0e 100644 --- a/src/url.rs +++ b/src/url.rs @@ -16,6 +16,9 @@ pub enum Error { #[error("URL has no fragment")] NoFragment, + + #[error("Unable to parse owner or repo")] + NoOwnerRepo, } #[derive(Debug)] @@ -34,6 +37,10 @@ impl FromStr for SuggestionUrl { .ok_or(Error::NoPath)? .collect::>(); + if path.len() < 2 { + return Err(Error::NoOwnerRepo); + } + Ok(SuggestionUrl { owner: path[0].to_owned(), repo: path[1].to_owned(), -- cgit v1.2.3