Properly escape URL parameters

This commit is contained in:
2022-05-27 23:37:54 +02:00
parent 32eb4676ee
commit bc3d4e1c49
5 changed files with 23 additions and 4 deletions

10
Cargo.lock generated
View File

@@ -347,6 +347,7 @@ dependencies = [
"shellexpand", "shellexpand",
"tempdir", "tempdir",
"toml", "toml",
"url-escape",
] ]
[[package]] [[package]]
@@ -1189,6 +1190,15 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "url-escape"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44e0ce4d1246d075ca5abec4b41d33e87a6054d08e2366b63205665e950db218"
dependencies = [
"percent-encoding",
]
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.15" version = "0.2.15"

View File

@@ -78,5 +78,8 @@ features = ["json"]
[dependencies.parse_link_header] [dependencies.parse_link_header]
version = "=0.3.2" version = "=0.3.2"
[dependencies.url-escape]
version = "=0.1.1"
[dev-dependencies.tempdir] [dev-dependencies.tempdir]
version = "=0.3.7" version = "=0.3.7"

View File

@@ -1,5 +1,6 @@
use serde::Deserialize; use serde::Deserialize;
use super::escape;
use super::ApiErrorResponse; use super::ApiErrorResponse;
use super::Filter; use super::Filter;
use super::JsonError; use super::JsonError;
@@ -108,7 +109,7 @@ impl Provider for Github {
user: &str, user: &str,
) -> Result<Vec<GithubProject>, ApiErrorResponse<GithubApiErrorResponse>> { ) -> Result<Vec<GithubProject>, ApiErrorResponse<GithubApiErrorResponse>> {
self.call_list( self.call_list(
&format!("{GITHUB_API_BASEURL}/users/{user}/repos"), &format!("{GITHUB_API_BASEURL}/users/{}/repos", escape(user)),
Some(ACCEPT_HEADER_JSON), Some(ACCEPT_HEADER_JSON),
) )
} }
@@ -118,7 +119,7 @@ impl Provider for Github {
group: &str, group: &str,
) -> Result<Vec<GithubProject>, ApiErrorResponse<GithubApiErrorResponse>> { ) -> Result<Vec<GithubProject>, ApiErrorResponse<GithubApiErrorResponse>> {
self.call_list( self.call_list(
&format!("{GITHUB_API_BASEURL}/orgs/{group}/repos?type=all"), &format!("{GITHUB_API_BASEURL}/orgs/{}/repos?type=all", escape(group)),
Some(ACCEPT_HEADER_JSON), Some(ACCEPT_HEADER_JSON),
) )
} }

View File

@@ -1,5 +1,6 @@
use serde::Deserialize; use serde::Deserialize;
use super::escape;
use super::ApiErrorResponse; use super::ApiErrorResponse;
use super::Filter; use super::Filter;
use super::JsonError; use super::JsonError;
@@ -125,7 +126,7 @@ impl Provider for Gitlab {
user: &str, user: &str,
) -> Result<Vec<GitlabProject>, ApiErrorResponse<GitlabApiErrorResponse>> { ) -> Result<Vec<GitlabProject>, ApiErrorResponse<GitlabApiErrorResponse>> {
self.call_list( self.call_list(
&format!("{}/api/v4/users/{}/projects", self.api_url(), user), &format!("{}/api/v4/users/{}/projects", self.api_url(), escape(user)),
Some(ACCEPT_HEADER_JSON), Some(ACCEPT_HEADER_JSON),
) )
} }
@@ -138,7 +139,7 @@ impl Provider for Gitlab {
&format!( &format!(
"{}/api/v4/groups/{}/projects?include_subgroups=true&archived=false", "{}/api/v4/groups/{}/projects?include_subgroups=true&archived=false",
self.api_url(), self.api_url(),
group escape(group),
), ),
Some(ACCEPT_HEADER_JSON), Some(ACCEPT_HEADER_JSON),
) )

View File

@@ -28,6 +28,10 @@ enum ProjectResponse<T, U> {
Failure(U), Failure(U),
} }
pub fn escape(s: &str) -> String {
url_escape::encode_component(s).to_string()
}
pub trait Project { pub trait Project {
fn into_repo_config( fn into_repo_config(
self, self,