diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-08-16 10:00:50 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-08-16 10:00:50 +0900 |
| commit | 112df62a01e482f33b68e1dac190f70085fcec64 (patch) | |
| tree | 19d126032309193cfd5f5d0fb63b6562ef17e5c9 /crates/shirabe/src/repository | |
| parent | 3fb08fab7ca69a028a9a89544b246ca70534cbce (diff) | |
| download | php-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.tar.gz php-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.tar.zst php-shirabe-112df62a01e482f33b68e1dac190f70085fcec64.zip | |
refactor(php-shim): give parse_url a typed UrlComponents result
parse_url now returns Option<UrlComponents> instead of a PhpMixed array,
and the component-selecting overload with the PHP_URL_* constants is gone:
callers read the field they want. Two call sites change behaviour as a
result, both towards PHP:
* CurlDownloader::handle_redirect tested scheme and host with is_null(), so
an unparsable Location header (PhpMixed::Bool(false)) counted as an
absolute URL. PHP's truthiness test sends it to the relative-path branch.
* Url::get_origin appended a literal port 0, which PHP treats as falsy and
leaves off.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
| -rw-r--r-- | crates/shirabe/src/repository/composer_repository.rs | 23 | ||||
| -rw-r--r-- | crates/shirabe/src/repository/vcs/github_driver.rs | 17 |
2 files changed, 15 insertions, 25 deletions
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 03439a7b..614df9e3 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -42,7 +42,7 @@ use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ AnyThrowable, CmpOp, InvalidArgumentException, LogicException, PHP_EOL, PhpMixed, RuntimeException, UnexpectedValueException, extension_loaded, hash, http_build_query_mixed, - json_decode, parse_url_all, php_regex, realpath, strtolower, strtr, urlencode, var_export, + json_decode, parse_url, php_regex, realpath, strtolower, strtr, urlencode, var_export, }; use shirabe_semver::CompilingMatcher; use shirabe_semver::constraint::AnyConstraint; @@ -207,13 +207,12 @@ impl ComposerRepository { .and_then(|v| v.as_string()) .unwrap_or("") .to_string(); - let url_bits = parse_url_all(&strtr(¤t_url, "\\", "/")); - let url_bits_arr = url_bits.as_array(); - let scheme_present = url_bits_arr - .and_then(|a| a.get("scheme")) - .and_then(|v| v.as_string()) - .is_some_and(|s| !s.is_empty()); - if url_bits_arr.is_none() || !scheme_present { + let url_bits = parse_url(&strtr(¤t_url, "\\", "/")); + let scheme_present = url_bits + .as_ref() + .and_then(|url_bits| url_bits.scheme.as_deref()) + .is_some_and(|scheme| !scheme.is_empty()); + if url_bits.is_none() || !scheme_present { return Err(UnexpectedValueException::new(format!( "Invalid url given for Composer repository: {}", current_url @@ -2100,13 +2099,11 @@ impl ComposerRepository { } pub fn get_packages_json_url(&self) -> String { - let json_url_parts = parse_url_all(&strtr(&self.url, "\\", "/")); + let json_url_parts = parse_url(&strtr(&self.url, "\\", "/")); let has_json = json_url_parts - .as_array() - .and_then(|a| a.get("path")) - .and_then(|v| v.as_string()) - .is_some_and(|p| p.contains(".json")); + .and_then(|json_url_parts| json_url_parts.path) + .is_some_and(|path| path.contains(".json")); if has_json { return self.url.clone(); } diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index 56ff3853..341d9f18 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -17,9 +17,9 @@ use indexmap::IndexMap; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_key_exists, array_map, + InvalidArgumentException, PhpMixed, RuntimeException, array_diff, array_map, array_search_mixed, base64_decode, basename, empty, explode, extension_loaded, in_array_loose, - parse_url_all, php_regex, strpos, strtolower, substr, trim, urlencode, + parse_url, php_regex, strpos, strtolower, substr, trim, urlencode, }; #[derive(Debug)] @@ -666,19 +666,12 @@ impl GitHubDriver { ); } "custom" => { - let bits = parse_url_all(&item_url); - if matches!(bits, PhpMixed::Bool(false)) { + let Some(bits) = parse_url(&item_url) else { keys_to_remove.push(key_idx); continue; - } - - let bits_map = match bits { - PhpMixed::Array(m) => m, - _ => IndexMap::new(), }; - if !array_key_exists("scheme", &bits_map) - && !array_key_exists("host", &bits_map) - { + + if bits.scheme.is_none() && bits.host.is_none() { if Preg::is_match(php_regex!(r"{^[a-z0-9-]++\.[a-z]{2,3}$}"), &item_url) { result[key_idx].insert( "url".to_string(), |
