Migrate to encodify

This commit is contained in:
Maurus Decimus
2026-09-28 10:45:15 +02:00
parent 42f7c87911
commit 5dc92c7329
29 changed files with 418 additions and 540 deletions
+3 -11
View File
@@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0 OR MIT
*/
use encodify::hex::decode_pair;
use url::Url;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -111,9 +112,9 @@ fn percent_decode(s: &str) -> String {
while i < bytes.len() {
if bytes[i] == b'%'
&& i + 2 < bytes.len()
&& let (Some(h), Some(l)) = (hex_val(bytes[i + 1]), hex_val(bytes[i + 2]))
&& let Some(byte) = decode_pair(bytes[i + 1], bytes[i + 2])
{
buf.push((h << 4) | l);
buf.push(byte);
i += 3;
continue;
}
@@ -126,15 +127,6 @@ fn percent_decode(s: &str) -> String {
}
}
fn hex_val(b: u8) -> Option<u8> {
match b {
b'0'..=b'9' => Some(b - b'0'),
b'a'..=b'f' => Some(b - b'a' + 10),
b'A'..=b'F' => Some(b - b'A' + 10),
_ => None,
}
}
fn percent_encode_safe(s: &str) -> String {
let mut out = String::with_capacity(s.len());
for byte in s.bytes() {