Skip to content

Commit fae176e

Browse files
fix: Handle case where parse fails on invalid port (#50)
Fixes #27 Applying fix provided in issue Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent de73852 commit fae176e

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [UNRELEASED]
99

10+
### Fixed
11+
12+
- Handle case where parse fails on invalid port ([#50](https://github.com/tjtelan/git-url-parse-rs/issues/50))
13+
14+
## [0.4.3](https://github.com/tjtelan/git-url-parse-rs/tree/v0.4.3) - 2022-10-11
15+
1016
### Added
1117

1218
- Add short git URL notation support ([#28](https://github.com/tjtelan/git-url-parse-rs/issues/28))

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ license = "MIT"
99
name = "git-url-parse"
1010
readme = "README.md"
1111
repository = "https://github.com/tjtelan/git-url-parse-rs"
12-
version = "0.4.3"
12+
version = "0.4.4"
1313

1414
[dependencies]
1515
tracing = "0.1"

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ pub fn normalize_url(url: &str) -> Result<Url> {
388388
}
389389
}
390390
}
391-
Err(_e) => {
392-
// e will most likely be url::ParseError::RelativeUrlWithoutBase
391+
Err(url::ParseError::RelativeUrlWithoutBase) => {
393392
// If we're here, we're only looking for Scheme::Ssh or Scheme::File
394393

395394
// Assuming we have found Scheme::Ssh if we can find an "@" before ":"
@@ -411,5 +410,8 @@ pub fn normalize_url(url: &str) -> Result<Url> {
411410
}
412411
}
413412
}
413+
Err(err) => {
414+
return Err(eyre!("url parsing failed: {:?}", err));
415+
}
414416
})
415417
}

tests/parse.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,18 @@ fn ssh_without_organization() {
367367
assert_eq!(parsed, expected);
368368
}
369369

370+
#[test]
371+
fn bad_port_number() {
372+
let test_url = "https://github.com:crypto-browserify/browserify-rsa.git";
373+
let e = GitUrl::parse(test_url);
374+
375+
assert!(e.is_err());
376+
assert_eq!(
377+
format!("{}", e.err().unwrap()),
378+
"Url normalization into url::Url failed"
379+
);
380+
}
381+
370382
#[test]
371383
fn git() {
372384
let test_url = "git:github.com/owner/name.git";

0 commit comments

Comments
 (0)