diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-15 09:10:16 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-15 09:10:16 +0900 |
| commit | 9e5bb3e4253dda96345f4d1a3421077a72295048 (patch) | |
| tree | 73237dd78c22e93fe6562a434bb5ffcb03055250 /crates | |
| parent | 8724f55749a97fe6a6e232d1dd900a069f9b7533 (diff) | |
| download | php-shirabe-9e5bb3e4253dda96345f4d1a3421077a72295048.tar.gz php-shirabe-9e5bb3e4253dda96345f4d1a3421077a72295048.tar.zst php-shirabe-9e5bb3e4253dda96345f4d1a3421077a72295048.zip | |
refactor(php-shim): take only the data argument in http_build_query
`http_build_query` ignores `numeric_prefix` because a string-keyed slice never
holds an integer key, and every caller passes `"&"` as the separator. Drop both
parameters and hard-code the separator.
Callers that pass a map of scalar literals to `http_build_query_mixed` no longer
need to build an `IndexMap<String, PhpMixed>` for it, so move them to the slice
form.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/shirabe-php-shim/src/url.rs | 10 | ||||
| -rw-r--r-- | crates/shirabe/src/installer/installation_manager.rs | 2 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs | 62 | ||||
| -rw-r--r-- | crates/shirabe/src/util/gitlab.rs | 26 |
4 files changed, 24 insertions, 76 deletions
diff --git a/crates/shirabe-php-shim/src/url.rs b/crates/shirabe-php-shim/src/url.rs index 27463ce0..c2ac725d 100644 --- a/crates/shirabe-php-shim/src/url.rs +++ b/crates/shirabe-php-shim/src/url.rs @@ -95,14 +95,8 @@ pub fn http_build_query_mixed( encode_pairs(&pairs, arg_separator) } -pub fn http_build_query( - data: &[(&str, &str)], - numeric_prefix: &str, - arg_separator: &str, -) -> String { - // numeric_prefix only applies to integer keys, which a string-keyed slice never has. - let _ = numeric_prefix; - encode_pairs(data, arg_separator) +pub fn http_build_query(data: &[(&str, &str)]) -> String { + encode_pairs(data, "&") } fn encode_pairs<T: serde::Serialize>(pairs: T, arg_separator: &str) -> String { diff --git a/crates/shirabe/src/installer/installation_manager.rs b/crates/shirabe/src/installer/installation_manager.rs index 2d21fb54..a9e66ccb 100644 --- a/crates/shirabe/src/installer/installation_manager.rs +++ b/crates/shirabe/src/installer/installation_manager.rs @@ -867,7 +867,7 @@ impl InstallationManager { .collect(); http.insert( "content".to_string(), - PhpMixed::String(http_build_query(¶ms_vec, "", "&")), + PhpMixed::String(http_build_query(¶ms_vec)), ); http.insert("timeout".to_string(), PhpMixed::Int(3)); opts.insert( diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index eb64c4f8..c3da08ff 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -19,8 +19,7 @@ use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ InvalidArgumentException, LogicException, PhpMixed, RuntimeException, array_key_exists, - array_search_mixed, extension_loaded, http_build_query_mixed, implode, is_array, php_regex, - strpos, + array_search_mixed, extension_loaded, http_build_query, implode, is_array, php_regex, strpos, }; #[derive(Debug)] @@ -152,18 +151,7 @@ impl GitBitbucketDriver { "https://api.bitbucket.org/2.0/repositories/{}/{}?{}", self.owner.clone(), self.repository.clone(), - http_build_query_mixed( - &{ - let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); - m.insert( - "fields".to_string(), - PhpMixed::String("-project,-owner".to_string()), - ); - m - }, - "", - "&", - ), + http_build_query(&[("fields", "-project,-owner")]), ); let repo_data = self @@ -524,23 +512,11 @@ impl GitBitbucketDriver { let mut resource = format!( "{}?{}", self.tags_url.clone(), - http_build_query_mixed( - &{ - let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); - m.insert("pagelen".to_string(), PhpMixed::Int(100)); - m.insert( - "fields".to_string(), - PhpMixed::String("values.name,values.target.hash,next".to_string()), - ); - m.insert( - "sort".to_string(), - PhpMixed::String("-target.date".to_string()), - ); - m - }, - "", - "&", - ), + http_build_query(&[ + ("pagelen", "100"), + ("fields", "values.name,values.target.hash,next"), + ("sort", "-target.date"), + ]), ); let mut has_next = true; while has_next { @@ -603,25 +579,11 @@ impl GitBitbucketDriver { let mut resource = format!( "{}?{}", self.branches_url.clone(), - http_build_query_mixed( - &{ - let mut m: IndexMap<String, PhpMixed> = IndexMap::new(); - m.insert("pagelen".to_string(), PhpMixed::Int(100)); - m.insert( - "fields".to_string(), - PhpMixed::String( - "values.name,values.target.hash,values.heads,next".to_string(), - ), - ); - m.insert( - "sort".to_string(), - PhpMixed::String("-target.date".to_string()), - ); - m - }, - "", - "&", - ), + http_build_query(&[ + ("pagelen", "100"), + ("fields", "values.name,values.target.hash,values.heads,next"), + ("sort", "-target.date"), + ]), ); let mut has_next = true; while has_next { diff --git a/crates/shirabe/src/util/gitlab.rs b/crates/shirabe/src/util/gitlab.rs index 73806762..3d1fb2be 100644 --- a/crates/shirabe/src/util/gitlab.rs +++ b/crates/shirabe/src/util/gitlab.rs @@ -425,15 +425,11 @@ impl GitLab { let headers = vec!["Content-Type: application/x-www-form-urlencoded".to_string()]; let api_url = origin_url; - let data = http_build_query( - &[ - ("username", username.as_str()), - ("password", password.as_str()), - ("grant_type", "password"), - ], - "", - "&", - ); + let data = http_build_query(&[ + ("username", username.as_str()), + ("password", password.as_str()), + ("grant_type", "password"), + ]); let mut http_inner: IndexMap<String, PhpMixed> = IndexMap::new(); http_inner.insert("method".to_string(), PhpMixed::String("POST".to_string())); http_inner.insert( @@ -498,14 +494,10 @@ impl GitLab { let headers = vec!["Content-Type: application/x-www-form-urlencoded".to_string()]; - let data = http_build_query( - &[ - ("refresh_token", refresh_token.as_str()), - ("grant_type", "refresh_token"), - ], - "", - "&", - ); + let data = http_build_query(&[ + ("refresh_token", refresh_token.as_str()), + ("grant_type", "refresh_token"), + ]); let mut http_inner = IndexMap::new(); http_inner.insert("method".to_string(), PhpMixed::String("POST".to_string())); http_inner.insert( |
