From 8c54214848dac3176cc406ef10ffac1e05d0ed0e Mon Sep 17 00:00:00 2001 From: Sebastiano Barezzi Date: Sun, 26 Jun 2022 19:02:32 +0200 Subject: fix(utils): Handle programming languages with spaces Change-Id: Ic0edc6bd6c94e0368dcf6910c8cbb56866127402 --- src/utils.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') 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 { 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::>()[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() )); } } -- cgit v1.2.3