Skip to content

Commit afefd02

Browse files
committed
engines/qwant: Parse url instead of using format
This makes sure that if a user uses & or any other symbol with special meaning their query won't get broken
1 parent 709425f commit afefd02

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/engines/qwant.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
//! by querying the upstream qwant search engine with user provided query and with a page
33
//! number if provided.
44
5+
use std::borrow::Cow;
56
use std::collections::HashMap;
67

78
use reqwest::header::HeaderMap;
8-
use reqwest::Client;
9+
use reqwest::{Client, Url};
910
use serde::Deserialize;
1011

1112
use crate::models::aggregation_models::SearchResult;
@@ -118,7 +119,20 @@ impl SearchEngine for Qwant {
118119
let results_per_page = 10;
119120
let start_result = results_per_page * page;
120121

121-
let url: String = format!("https://api.qwant.com/v3/search/web?q={query}&count={results_per_page}&locale=en_US&offset={start_result}&safesearch={safe_search}&device=desktop&tgp=2&displayed=true");
122+
let url = Url::parse_with_params(
123+
"https://api.qwant.com/v3/search/web",
124+
&[
125+
("q", Cow::from(query)),
126+
("count", results_per_page.to_string().into()),
127+
("locale", "en_US".into()),
128+
("offset", start_result.to_string().into()),
129+
("safesearch", safe_search.to_string().into()),
130+
("device", "desktop".into()),
131+
("tgb", "2".into()),
132+
("displayed", "true".into()),
133+
],
134+
)
135+
.change_context(EngineError::UnexpectedError)?;
122136

123137
let header_map = HeaderMap::try_from(&HashMap::from([
124138
("User-Agent".to_string(), user_agent.to_string()),

0 commit comments

Comments
 (0)