diff options
| author | Lorenz Leitner <lrnz.ltnr@gmail.com> | 2021-10-15 11:44:23 +0200 |
|---|---|---|
| committer | Lorenz Leitner <lrnz.ltnr@gmail.com> | 2021-10-15 11:44:23 +0200 |
| commit | 587dc0283f3c48e71299a02e46118271750f94cb (patch) | |
| tree | 59f78080a9a8d0959642b1b32e020b6dc08c8df1 /src/hooks | |
| parent | Remove patch versions (diff) | |
Also quote_plus on API url input query string
Diffstat (limited to '')
| -rw-r--r-- | src/hooks/wolfram_alpha.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/hooks/wolfram_alpha.rs b/src/hooks/wolfram_alpha.rs index 70a771c..3faddbf 100644 --- a/src/hooks/wolfram_alpha.rs +++ b/src/hooks/wolfram_alpha.rs @@ -64,12 +64,16 @@ fn to_single_string(wa_res: WaResponse) -> String { .join(" - ") } -fn get_url(query_str: &str, api_key: Option<&str>, base_url: Option<&str>) -> Result<Url, Error> { +fn get_wa_api_url( + query_str: &str, + api_key: Option<&str>, + base_url: Option<&str>, +) -> Result<Url, Error> { let wa_url = "http://api.wolframalpha.com"; let api_url = format!( "{}/v2/query?input={}&appid={}&output=json", base_url.unwrap_or(wa_url), - query_str, + quote_plus(query_str)?, api_key.unwrap_or("XXX"), // Allow tests to run without a key ); Url::parse(&api_url).context("Failed to parse URL") @@ -110,7 +114,7 @@ async fn wa_query( base_url: Option<&str>, ) -> Result<String, Error> { let user_url_shortened_fut = get_wa_user_short_url(query_str); - let url = get_url(query_str, api_key, base_url)?; + let url = get_wa_api_url(query_str, api_key, base_url)?; let wa_res_fut = handle_wa_req(&url); let futs = join!(wa_res_fut, user_url_shortened_fut); |
