aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-06-26 16:34:11 -0700
committerGitHub <[email protected]>2022-06-26 16:34:11 -0700
commit0e46418c424604fcd95ce439301fb2ffd5378695 (patch)
tree37bdf5fb8cf58da4ed2198aa5d0d07ab61b925c6
parentMerge branch 'main' of https://github.com/senpy-club/api-worker (diff)
parentfix(utils): Handle programming languages with spaces (diff)
downloadapi-worker-0e46418c424604fcd95ce439301fb2ffd5378695.tar.xz
api-worker-0e46418c424604fcd95ce439301fb2ffd5378695.zip
Merge pull request #18 from SebaUbuntu/main
fix(utils): Handle programming languages with spaces
-rw-r--r--Cargo.toml1
-rw-r--r--src/utils.rs12
2 files changed, 8 insertions, 5 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 0cf1dd4..7da9617 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -34,6 +34,7 @@ serde_json = "1.0.79"
getrandom = { version = "0.2.6", features = ["js"] }
rand = "0.8.5"
dotenv = "0.15.0"
+urlparse = "0.7.3"
# Worker
worker = "0.0.9"
diff --git a/src/utils.rs b/src/utils.rs
index c42c15c..242cd77 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -20,6 +20,9 @@ use std::{lazy::SyncLazy, sync::Mutex};
use worker::Cors;
+use urlparse::quote;
+use urlparse::unquote;
+
use crate::{
constants,
structures::{GitHubAPIResponse, Type},
@@ -130,8 +133,8 @@ pub async fn filter_images_by_language(
) -> Vec<String> {
let mut images = vec![];
- // URL (percent) encoding of pound symbol to pound symbol
- let language = language.replace("%23", "#");
+ // URL (percent) decoding
+ let language = unquote(language).ok().unwrap();
for item in github_api(repository.clone()).await.unwrap().tree {
if item.path.split('/').collect::<Vec<&str>>()[0] == language
@@ -144,9 +147,8 @@ pub async fn filter_images_by_language(
} else {
&*boys::GITHUB_USER_CONTENT
},
- // Pound symbols to URL (percent) encoding of pound symbol because we
- // are pushing a URL, not a string
- item.path.replace('#', "%23")
+ // URL (percent) encoding because we are pushing a URL, not a string
+ quote(item.path, b"").ok().unwrap()
));
}
}