Skip to content

Commit c387851

Browse files
committed
Read the packagist host through url_hostname
A packagist repository URL with user:pass@ userinfo was read as the username, so the transport-options restore warning was skipped for it. Use the shared url_hostname helper, which skips userinfo and the port. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c1affdf commit c387851

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

  • crates/socket-patch-core/src/patch/redirect/upstream

‎crates/socket-patch-core/src/patch/redirect/upstream/composer.rs‎

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ use crate::crawlers::composer_crawler::normalize_version;
3232
use crate::formats::composer::hosted::{
3333
find_composer_entry, find_composer_member, json_string_field, ComposerEntry,
3434
};
35+
use crate::utils::redact::url_hostname;
3536

3637
const COMPOSER_LOCK: &str = "composer.lock";
3738
/// The `notification-url` composer records for packagist packages.
@@ -141,11 +142,13 @@ fn packagist_declares_options(composer_json: Option<&str>) -> bool {
141142
};
142143
let packagist_with_options = |r: &Value| {
143144
r.get("options").is_some_and(|o| !o.is_null())
144-
&& r.get("url").and_then(Value::as_str).is_some_and(|u| {
145-
let host = u.split("://").nth(1).unwrap_or(u);
146-
let host = host.split(['/', ':']).next().unwrap_or("");
147-
host == "packagist.org" || host.ends_with(".packagist.org")
148-
})
145+
&& r.get("url")
146+
.and_then(Value::as_str)
147+
.and_then(url_hostname)
148+
.is_some_and(|host| {
149+
let host = host.to_ascii_lowercase();
150+
host == "packagist.org" || host.ends_with(".packagist.org")
151+
})
149152
};
150153
match doc.get("repositories") {
151154
Some(Value::Array(a)) => a.iter().any(packagist_with_options),
@@ -515,6 +518,10 @@ mod tests {
515518
r#"{"repositories": {"private": {"type": "composer", "url": "https://r.example",
516519
"options": {"http": {"header": ["X-Token: t"]}}}}}"#
517520
)));
521+
assert!(packagist_declares_options(Some(
522+
r#"{"repositories": [{"type": "composer", "url": "https://u:p@repo.packagist.org",
523+
"options": {"ssl": {"verify_peer": false}}}]}"#
524+
)));
518525
assert!(!packagist_declares_options(Some(
519526
r#"{"repositories": [{"type": "composer", "url": "https://packagist.org.evil.example",
520527
"options": {"http": {"header": ["X-Token: t"]}}}]}"#

0 commit comments

Comments
 (0)