From c9306afc1ca5b5a91b4f61c3cd5d1392408c3a58 Mon Sep 17 00:00:00 2001 From: Samuel Gordalina Date: Mon, 24 Jan 2022 21:22:29 -0800 Subject: [PATCH] Allow underscores in web url --- src/Adapter/Http/SymfonyHttpClient.php | 2 +- tests/Adapter/Http/FileGetContentsTest.php | 8 +++++++- tests/Adapter/Http/SymfonyHttpClientTest.php | 8 +++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Adapter/Http/SymfonyHttpClient.php b/src/Adapter/Http/SymfonyHttpClient.php index 831e652..84fdc3e 100644 --- a/src/Adapter/Http/SymfonyHttpClient.php +++ b/src/Adapter/Http/SymfonyHttpClient.php @@ -29,7 +29,7 @@ public function fetch($filename) try { $url = "{$this->baseUrl}/{$filename}"; - if (!filter_var($url, FILTER_VALIDATE_URL)) { + if (!parse_url($url, PHP_URL_HOST)) { throw new \RuntimeException( sprintf( "The given url is not valid: %s, did you forget to specify the --web-url option?", diff --git a/tests/Adapter/Http/FileGetContentsTest.php b/tests/Adapter/Http/FileGetContentsTest.php index bae501a..c24539c 100644 --- a/tests/Adapter/Http/FileGetContentsTest.php +++ b/tests/Adapter/Http/FileGetContentsTest.php @@ -13,7 +13,7 @@ class FileGetContentsTest extends \PHPUnit\Framework\TestCase public static function setUpBeforeClass(): void { - self::$process = new Process(['php', '-S', 'localhost:9999', '-t', '.']); + self::$process = new Process(['php', '-S', '127.0.0.1:9999', '-t', '.']); self::$process->start(); usleep(100000); //wait for server to get going @@ -30,6 +30,12 @@ public function testFetch() $this->assertStringStartsWith('# CacheTool', $client->fetch('README.md')); } + public function testFetchUnderscores() + { + $client = new SymfonyHttpClient('http://_.127.0.0.1.sslip.io:9999'); + $this->assertStringStartsWith('# CacheTool', $client->fetch('README.md')); + } + public function testFetchFailed() { $client = new FileGetContents('http://localhost:9999'); diff --git a/tests/Adapter/Http/SymfonyHttpClientTest.php b/tests/Adapter/Http/SymfonyHttpClientTest.php index 055b5e7..6021aee 100644 --- a/tests/Adapter/Http/SymfonyHttpClientTest.php +++ b/tests/Adapter/Http/SymfonyHttpClientTest.php @@ -13,7 +13,7 @@ class SymfonyHttpClientTest extends \PHPUnit\Framework\TestCase public static function setUpBeforeClass(): void { - self::$process = new Process(['php', '-S', 'localhost:9999', '-t', '.']); + self::$process = new Process(['php', '-S', '127.0.0.1:9999', '-t', '.']); self::$process->start(); usleep(100000); //wait for server to get going @@ -30,6 +30,12 @@ public function testFetch() $this->assertStringStartsWith('# CacheTool', $client->fetch('README.md')); } + public function testFetchUnderscores() + { + $client = new SymfonyHttpClient('http://_.127.0.0.1.sslip.io:9999'); + $this->assertStringStartsWith('# CacheTool', $client->fetch('README.md')); + } + public function testFetchFailed() { $client = new SymfonyHttpClient('http://localhost:9999');