From 924527cda6a17b18718c65cfb8f08ba054920619 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 10 Jan 2025 16:42:50 +0100 Subject: [PATCH] Allow using short form URLs like foo.com if they are very simple --- src/Composer/Repository/Vcs/GitHubDriver.php | 5 +++++ .../Test/Repository/Vcs/GitHubDriverTest.php | 22 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Composer/Repository/Vcs/GitHubDriver.php b/src/Composer/Repository/Vcs/GitHubDriver.php index 31399f190..12f81189d 100644 --- a/src/Composer/Repository/Vcs/GitHubDriver.php +++ b/src/Composer/Repository/Vcs/GitHubDriver.php @@ -301,6 +301,11 @@ class GitHubDriver extends VcsDriver } if (!array_key_exists('scheme', $bits) && !array_key_exists('host', $bits)) { + if (Preg::isMatch('{^[a-z0-9-]++\.[a-z]{2,3}$}', $item['url'])) { + $result[$key]['url'] = 'https://'.$item['url']; + break; + } + $this->io->writeError('Funding URL '.$item['url'].' not in a supported format.'); unset($result[$key]); break; diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index 4be3a3816..ff580ac6a 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -288,11 +288,21 @@ class GitHubDriverTest extends TestCase return [ [ 'custom: example.com', - null, + [ + [ + 'type' => 'custom', + 'url' => 'https://example.com', + ], + ], ], [ 'custom: [example.com]', - null, + [ + [ + 'type' => 'custom', + 'url' => 'https://example.com', + ], + ], ], [ 'custom: "https://example.com"', @@ -319,6 +329,10 @@ class GitHubDriverTest extends TestCase 'type' => 'custom', 'url' => 'https://example.com', ], + [ + 'type' => 'custom', + 'url' => 'https://example.org', + ], ], ], [ @@ -328,6 +342,10 @@ class GitHubDriverTest extends TestCase 'type' => 'custom', 'url' => 'https://example.com', ], + [ + 'type' => 'custom', + 'url' => 'https://example.org', + ], ], ], ];