Skip to content

Commit 650461c

Browse files
committed
Merge branch 'url-set-password'
2 parents c5a7e66 + 6b10245 commit 650461c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

gix-url/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ impl Url {
124124
self.user = user;
125125
prev
126126
}
127+
128+
/// Set the given `password`, or unset it with `None`. Return the previous value.
129+
pub fn set_password(&mut self, password: Option<String>) -> Option<String> {
130+
let prev = self.password.take();
131+
self.password = password;
132+
prev
133+
}
127134
}
128135

129136
/// Builder

gix-url/tests/access/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,28 @@ mod canonicalized {
3030
}
3131
}
3232

33+
#[test]
34+
fn password() -> crate::Result {
35+
let mut url = gix_url::parse("https://user:password@host/path".into())?;
36+
37+
assert_eq!(url.password(), Some("password"));
38+
assert_eq!(url.set_password(Some("new-pass".into())), Some("password".into()));
39+
assert_eq!(url.password(), Some("new-pass"));
40+
41+
Ok(())
42+
}
43+
44+
#[test]
45+
fn user() -> crate::Result {
46+
let mut url = gix_url::parse("https://user:password@host/path".into())?;
47+
48+
assert_eq!(url.user(), Some("user"));
49+
assert_eq!(url.set_user(Some("new-user".into())), Some("user".into()));
50+
assert_eq!(url.user(), Some("new-user"));
51+
52+
Ok(())
53+
}
54+
3355
#[test]
3456
fn host_argument_safe() -> crate::Result {
3557
let url = gix_url::parse("ssh://-oProxyCommand=open$IFS-aCalculator/foo".into())?;

0 commit comments

Comments
 (0)