From 112df62a01e482f33b68e1dac190f70085fcec64 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 10:00:50 +0900 Subject: refactor(php-shim): give parse_url a typed UrlComponents result parse_url now returns Option 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) --- crates/shirabe/src/config.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'crates/shirabe/src/config.rs') diff --git a/crates/shirabe/src/config.rs b/crates/shirabe/src/config.rs index be06bb21..5d990c55 100644 --- a/crates/shirabe/src/config.rs +++ b/crates/shirabe/src/config.rs @@ -10,8 +10,8 @@ use crate::io::io_interface; use indexmap::IndexMap; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ - E_USER_DEPRECATED, PHP_URL_HOST, PHP_URL_SCHEME, PhpMixed, RuntimeException, array_key_exists, - array_merge, array_search_mixed, array_unique, empty, filter_var_url, implode, in_array_loose, + E_USER_DEPRECATED, PhpMixed, RuntimeException, array_key_exists, array_merge, + array_search_mixed, array_unique, empty, filter_var_url, implode, in_array_loose, in_array_strict, intval, is_array, is_string, parse_url, php_regex, php_to_string, rtrim, strtolower, strtoupper, strtr, substr, trigger_error, }; @@ -1035,12 +1035,9 @@ impl Config { } // Extract scheme and throw exception on known insecure protocols - let scheme = parse_url(url, PHP_URL_SCHEME) - .as_string() - .map(|s| s.to_string()); - let hostname = parse_url(url, PHP_URL_HOST) - .as_string() - .map(|s| s.to_string()); + let parsed = parse_url(url); + let scheme = parsed.as_ref().and_then(|parsed| parsed.scheme.clone()); + let hostname = parsed.and_then(|parsed| parsed.host); if matches!(scheme.as_deref(), Some("http" | "git" | "ftp" | "svn")) { if self.get_with_flags("secure-http", 0)?.as_bool() == Some(true) { if scheme.as_deref() == Some("svn") { -- cgit v1.3.1-4-g156e