Skip to content

Commit a215706

Browse files
committed
Have append_query_params take iterator over &strs
1 parent 6358157 commit a215706

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

bitreq/fuzz/src/url_parse.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub fn do_test(data: &[u8]) {
8686
{
8787
let mut url_clone = bitreq_url.clone();
8888
// Use the input itself as both key and value to exercise encoding
89-
url_clone.append_query_params([(input.to_string(), input.to_string())]);
89+
url_clone.append_query_params([(&*input, &*input)]);
9090
// Verify the URL is still valid by accessing its fields
9191
let _ = url_clone.query();
9292
let _ = url_clone.as_str();
@@ -98,10 +98,7 @@ pub fn do_test(data: &[u8]) {
9898

9999
// Test appending multiple params in one call
100100
let mut url_clone3 = bitreq_url.clone();
101-
url_clone3.append_query_params([
102-
("key1".into(), "value1".into()),
103-
("key2".into(), input.to_string()),
104-
]);
101+
url_clone3.append_query_params([("key1", "value1"), ("key2", &input)]);
105102
let _ = url_clone3.as_str();
106103
}
107104

bitreq/src/request.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ impl ParsedRequest {
364364
#[allow(unused_mut)]
365365
pub(crate) fn new(mut config: Request) -> Result<ParsedRequest, Error> {
366366
let mut url = Url::parse(&config.url)?;
367-
url.append_query_params(config.params.drain(..));
367+
let params = config.params.iter().map(|(a, b)| (a.as_str(), b.as_str()));
368+
url.append_query_params(params);
368369

369370
#[cfg(all(feature = "proxy", feature = "std"))]
370371
// Set default proxy from environment variables

bitreq/src/url.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ impl Url {
418418
/// Otherwise, the first parameter is appended with `?`.
419419
///
420420
/// Only calls `parse_inner` once after all parameters have been appended.
421-
pub fn append_query_params(&mut self, params: impl IntoIterator<Item = (String, String)>) {
421+
pub fn append_query_params<'a>(&mut self, params: impl IntoIterator<Item = (&'a str, &'a str)>) {
422422
let mut params = params.into_iter().peekable();
423423
if params.peek().is_none() {
424424
return;
@@ -1037,7 +1037,7 @@ mod tests {
10371037
#[test]
10381038
fn append_query_params_empty_iterator() {
10391039
let mut url = Url::parse("http://example.com/path").unwrap();
1040-
url.append_query_params(std::iter::empty::<(String, String)>());
1040+
url.append_query_params(std::iter::empty::<(&str, &str)>());
10411041
assert_eq!(url.query(), None);
10421042
assert_eq!(url.as_str(), "http://example.com/path");
10431043
}

0 commit comments

Comments
 (0)