diff options
| author | Teddy Wing | 2020-08-01 01:19:16 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2020-08-01 01:19:16 +0200 | 
| commit | 25ce03b6102cf017cf9cbba7e28dbd0d76ab5a5d (patch) | |
| tree | 42216fb1a0a7767cc14f51314be4fcc46a02c000 | |
| parent | 2b54af9f5e0ddd1233771b163588cc7b409988b1 (diff) | |
| download | git-suggestion-25ce03b6102cf017cf9cbba7e28dbd0d76ab5a5d.tar.bz2 | |
SuggestionUrl: Return an error if path has less than two segments
We need two segments in the path to parse the owner-repo combination.
| -rw-r--r-- | src/url.rs | 7 | 
1 files changed, 7 insertions, 0 deletions
| @@ -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::<Vec<_>>(); +        if path.len() < 2 { +            return Err(Error::NoOwnerRepo); +        } +          Ok(SuggestionUrl {              owner: path[0].to_owned(),              repo: path[1].to_owned(), | 
