-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(parser): allow
-
(hyphen) to appear in usernames (#203)
- Loading branch information
1 parent
4fb9045
commit 8009cc9
Showing
2 changed files
with
33 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ fn parse_scheme(s: &str) -> PResult<&str> { | |
|
||
fn parse_username_password(s: &str) -> PResult<(Option<&str>, Option<&str>)> { | ||
let (auth, remaining) = s.split_once('@').ok_or("Auth missing @")?; | ||
let (auth, username) = maybe(parse_until(|c| !c.is_alphanumeric()))(auth)?; | ||
let (auth, username) = maybe(parse_until(|c| !c.is_alphanumeric() && c != '-'))(auth)?; | ||
let (auth, password) = maybe(prefixed( | ||
parse_char(':'), | ||
parse_until(|c| !c.is_alphanumeric()), | ||
|
@@ -331,6 +331,24 @@ mod tests { | |
assert_eq!(username_password.1, Some("password")); | ||
} | ||
|
||
#[test] | ||
fn should_return_username_with_hyphen_and_password() { | ||
let (s, username_password) = | ||
parse_username_password("some-user:password@").unwrap(); | ||
assert_eq!(s, ""); | ||
assert_eq!(username_password.0, Some("some-user")); | ||
assert_eq!(username_password.1, Some("password")); | ||
} | ||
|
||
#[test] | ||
fn should_return_username_password_if_username_starts_or_ends_with_hyphen() { | ||
let (s, username_password) = | ||
parse_username_password("-some-user-:password@").unwrap(); | ||
assert_eq!(s, ""); | ||
assert_eq!(username_password.0, Some("-some-user-")); | ||
assert_eq!(username_password.1, Some("password")); | ||
} | ||
|
||
#[test] | ||
fn should_consume_up_to_the_ending_sequence() { | ||
let (s, username_password) = | ||
|
@@ -653,6 +671,16 @@ mod tests { | |
assert_eq!(destination.port, Some(22)); | ||
} | ||
|
||
#[test] | ||
fn parse_should_succeed_if_given_username_has_hyphen() { | ||
let destination = parse("[email protected]:22").unwrap(); | ||
assert_eq!(destination.scheme, None); | ||
assert_eq!(destination.username.as_deref(), Some("some-user")); | ||
assert_eq!(destination.password, None); | ||
assert_eq!(destination.host, "example.com"); | ||
assert_eq!(destination.port, Some(22)); | ||
} | ||
|
||
#[test] | ||
fn parse_should_succeed_if_given_password_host_and_port() { | ||
let destination = parse(":[email protected]:22").unwrap(); | ||
|