From 90828cc71c968a3ee92f637253cb6da11d4a20c7 Mon Sep 17 00:00:00 2001 From: Mario A <10923513+Midblyte@users.noreply.github.com> Date: Sat, 21 May 2022 05:48:59 +0000 Subject: [PATCH] Fix "Post url contains non-ASCII characters" error (#479) --- Cargo.lock | 1 + Cargo.toml | 1 + src/client.rs | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index dbef214..f138b37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -596,6 +596,7 @@ dependencies = [ "futures-lite", "hyper", "hyper-rustls", + "percent-encoding", "regex", "route-recognizer", "rust-embed", diff --git a/Cargo.toml b/Cargo.toml index d7033de..5c856cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ cookie = "0.16.0" futures-lite = "1.12.0" hyper = { version = "0.14.18", features = ["full"] } hyper-rustls = "0.23.0" +percent-encoding = "2.1.0" route-recognizer = "0.3.1" serde_json = "1.0.81" tokio = { version = "1.18.2", features = ["full"] } diff --git a/src/client.rs b/src/client.rs index 864a6c6..da271dd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,6 +1,7 @@ use cached::proc_macro::cached; use futures_lite::{future::Boxed, FutureExt}; use hyper::{body::Buf, client, Body, Request, Response, Uri}; +use percent_encoding::{percent_encode, CONTROLS}; use serde_json::Value; use std::result::Result; @@ -90,7 +91,7 @@ fn request(url: String, quarantine: bool) -> Boxed, String .headers() .get("Location") .map(|val| { - let new_url = val.to_str().unwrap_or_default(); + let new_url = percent_encode(val.as_bytes(), CONTROLS).to_string(); format!("{}{}raw_json=1", new_url, if new_url.contains('?') { "&" } else { "?" }) }) .unwrap_or_default()