From 9a65fadd52cb4c2a48722de5797d55af8f80cfc1 Mon Sep 17 00:00:00 2001 From: "T.J. Telan" Date: Fri, 4 Nov 2022 18:42:26 -0700 Subject: [PATCH 1/3] fix: Handle case where parse fails on invalid port Fixes #27 Applying fix provided in issue --- src/lib.rs | 6 ++++-- tests/parse.rs | 12 ++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 60f7bc0..cad821d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -388,8 +388,7 @@ pub fn normalize_url(url: &str) -> Result { } } } - Err(_e) => { - // e will most likely be url::ParseError::RelativeUrlWithoutBase + Err(url::ParseError::RelativeUrlWithoutBase) => { // If we're here, we're only looking for Scheme::Ssh or Scheme::File // Assuming we have found Scheme::Ssh if we can find an "@" before ":" @@ -411,5 +410,8 @@ pub fn normalize_url(url: &str) -> Result { } } } + Err(err) => { + return Err(eyre!("url parsing failed: {:?}", err)); + } }) } diff --git a/tests/parse.rs b/tests/parse.rs index a30306f..4bc55a4 100644 --- a/tests/parse.rs +++ b/tests/parse.rs @@ -367,6 +367,18 @@ fn ssh_without_organization() { assert_eq!(parsed, expected); } +#[test] +fn bad_port_number() { + let test_url = "https://github.com:crypto-browserify/browserify-rsa.git"; + let e = GitUrl::parse(test_url); + + assert!(e.is_err()); + assert_eq!( + format!("{}", e.err().unwrap()), + "Url normalization into url::Url failed" + ); +} + #[test] fn git() { let test_url = "git:github.com/owner/name.git"; From a8a90b5837b58c13f1eee41567c462e6555cd926 Mon Sep 17 00:00:00 2001 From: "T.J. Telan" Date: Fri, 4 Nov 2022 19:08:28 -0700 Subject: [PATCH 2/3] Update crate version for release --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 1354e78..4b6c907 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ license = "MIT" name = "git-url-parse" readme = "README.md" repository = "https://github.com/tjtelan/git-url-parse-rs" -version = "0.4.3" +version = "0.4.4" [dependencies] tracing = "0.1" From 63cbf4342d00054ef18d3c958eb9ff98e86c09f1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 5 Nov 2022 02:26:55 +0000 Subject: [PATCH 3/3] Updating CHANGELOG.md and/or MSRV badge [actions skip] --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df208cb..bf49357 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [UNRELEASED] +### Fixed + +- Handle case where parse fails on invalid port ([#50](https://github.com/tjtelan/git-url-parse-rs/issues/50)) + +## [0.4.3](https://github.com/tjtelan/git-url-parse-rs/tree/v0.4.3) - 2022-10-11 + ### Added - Add short git URL notation support ([#28](https://github.com/tjtelan/git-url-parse-rs/issues/28))