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/util/url.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'crates/shirabe/src/util/url.rs') diff --git a/crates/shirabe/src/util/url.rs b/crates/shirabe/src/util/url.rs index c7cbd228..ea9e4401 100644 --- a/crates/shirabe/src/util/url.rs +++ b/crates/shirabe/src/util/url.rs @@ -4,17 +4,14 @@ use crate::config::Config; use crate::util::GitHub; use indexmap::IndexMap; use shirabe_pcre::{CaptureKey, Preg}; -use shirabe_php_shim::{ - PHP_URL_HOST, PHP_URL_PORT, PhpMixed, in_array_strict, parse_url, php_regex, -}; +use shirabe_php_shim::{PhpMixed, in_array_strict, parse_url, php_regex}; pub struct Url; impl Url { pub fn update_dist_reference(config: &Config, mut url: String, r#ref: &str) -> String { - let host = parse_url(&url, PHP_URL_HOST) - .as_string() - .map(|s| s.to_string()) + let host = parse_url(&url) + .and_then(|parsed| parsed.host) .unwrap_or_default(); if host == "api.github.com" || host == "github.com" || host == "www.github.com" { @@ -121,11 +118,15 @@ impl Url { return url.to_string(); } - let mut origin = parse_url(url, PHP_URL_HOST) - .as_string() - .map(|s| s.to_string()) + let parsed = parse_url(url); + let mut origin = parsed + .as_ref() + .and_then(|parsed| parsed.host.clone()) .unwrap_or_default(); - if let Some(port) = parse_url(url, PHP_URL_PORT).as_int() { + if let Some(port) = parsed + .and_then(|parsed| parsed.port) + .filter(|port| *port != 0) + { origin = format!("{}:{}", origin, port); } -- cgit v1.3.1-4-g156e