aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2020-08-01 01:19:16 +0200
committerTeddy Wing2020-08-01 01:19:16 +0200
commit25ce03b6102cf017cf9cbba7e28dbd0d76ab5a5d (patch)
tree42216fb1a0a7767cc14f51314be4fcc46a02c000
parent2b54af9f5e0ddd1233771b163588cc7b409988b1 (diff)
downloadgit-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.rs7
1 files changed, 7 insertions, 0 deletions
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::<Vec<_>>();
+ if path.len() < 2 {
+ return Err(Error::NoOwnerRepo);
+ }
+
Ok(SuggestionUrl {
owner: path[0].to_owned(),
repo: path[1].to_owned(),