fix(parser): allow `-` (hyphen) to appear in usernames (#203)

pull/207/head
Nagy Botond 11 months ago committed by GitHub
parent 4fb9045152
commit 8009cc9361
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -57,6 +57,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `crossbeam-channel` dependency removed from notify by disabling its feature
in order to avoid a `tokio::spawn` issue (https://github.com/notify-rs/notify/issues/380)
### Fixed
- usernames with `-` (hyphen) we're rejected as invalid
## [0.20.0-alpha.7]
### Added

@ -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("some-user@example.com: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(":password@example.com:22").unwrap();

Loading…
Cancel
Save