Skip to content

Commit 309f283

Browse files
committed
Merge pull request #183 from millerjs/master
Handle malformed percent-encoding
2 parents 4a4d4c9 + 0c54f01 commit 309f283

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/url.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,17 @@ fn decode_inner(c: &str, full_url: bool) -> DecodeResult<String> {
131131
}
132132
};
133133

134+
let bytes_from_hex = match Vec::<u8>::from_hex(&bytes) {
135+
Ok(b) => b,
136+
_ => {
137+
return Err("Malformed input: found '%' followed by \
138+
invalid hex values. Character '%' must \
139+
escaped.".to_owned())
140+
}
141+
};
142+
134143
// Only decode some characters if full_url:
135-
match Vec::<u8>::from_hex(&bytes).unwrap()[0] as char {
144+
match bytes_from_hex[0] as char {
136145
// gen-delims:
137146
':' |
138147
'/' |

tests/test.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,11 @@ fn test_get_opt_wrong_type() {
938938
}
939939
}
940940

941+
#[test]
942+
fn url_unencoded_password() {
943+
assert!("postgresql://username:password%1*@localhost".into_connect_params().is_err())
944+
}
945+
941946
#[test]
942947
fn url_encoded_password() {
943948
let params = "postgresql://username%7b%7c:password%7b%7c@localhost".into_connect_params().unwrap();

0 commit comments

Comments
 (0)