Fix percent-encoded usernames and passwords

Closes #113
This commit is contained in:
Steven Fackler 2015-04-15 20:31:15 -07:00
parent 2eea62fed2
commit 411a8c495c
2 changed files with 11 additions and 3 deletions

View File

@ -309,13 +309,13 @@ fn get_authority(rawurl: &str) ->
colon_count = 0; // reset count
match st {
State::Start => {
let user = rawurl[begin..i].to_string();
let user = try!(decode_component(&rawurl[begin..i]));
userinfo = Some(UserInfo::new(user, None));
st = State::InHost;
}
State::PassHostPort => {
let user = rawurl[begin..pos].to_string();
let pass = rawurl[pos+1..i].to_string();
let user = try!(decode_component(&rawurl[begin..pos]));
let pass = try!(decode_component(&rawurl[pos+1..i]));
userinfo = Some(UserInfo::new(user, Some(pass)));
st = State::InHost;
}

View File

@ -17,6 +17,7 @@ use postgres::{HandleNotice,
Error,
ConnectError,
DbError,
IntoConnectParams,
VecStreamIterator};
use postgres::SqlState::{SyntaxError,
QueryCanceled,
@ -936,3 +937,10 @@ fn test_get_opt_wrong_type() {
Err(e) => panic!("unexpected error {}", e),
}
}
#[test]
fn url_encoded_password() {
let params = "postgresql://username%7b%7c:password%7b%7c@localhost".into_connect_params().unwrap();
assert_eq!("username{|", &params.user.as_ref().unwrap().user[..]);
assert_eq!("password{|", &params.user.as_ref().unwrap().password.as_ref().unwrap()[..]);
}