From d3ef9bb8c13cb052ad1e2eb026d706c5f66c799b Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 22 May 2020 14:48:34 -0400 Subject: [PATCH] Fix last URL test failures --- lib/Url.php | 8 ++++---- tests/cases/Util/Url/Psr7TestCase.php | 1 - tests/cases/Util/Url/UrlTest.php | 3 ++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Url.php b/lib/Url.php index 5110c8b..1fc3c4a 100644 --- a/lib/Url.php +++ b/lib/Url.php @@ -64,8 +64,8 @@ PCRE; protected const IPV4_PATTERN = '/^[\.xX0-9a-fA-F\x{ff10}-\x{ff19}\x{ff21}-\x{ff26}\x{ff41}-\x{ff46}\x{ff38}\x{ff58}\x{ff0e}]*$/u'; // matches ASCII and fullwidth equivalents protected const IPV6_PATTERN = '/^\[[^\]]+\]$/i'; protected const PORT_PATTERN = '/^\d*$/'; - protected const FORBIDDEN_HOST_PATTERN = '/[\x{00}\t\n\r #%\/:\?@\[\]\\\]/'; - protected const FORBIDDEN_OPAQUE_HOST_PATTERN = '/[\x{00}\t\n\r #\/:\?@\[\]\\\]/'; // forbidden host excluding % + protected const FORBIDDEN_HOST_PATTERN = '/[\x{00}\t\n\r #%\/:<>\?@\[\]\\\^]/'; + protected const FORBIDDEN_OPAQUE_HOST_PATTERN = '/[\x{00}\t\n\r #\/:<>\?@\[\]\\\^]/'; // forbidden host excluding % protected const WINDOWS_AUTHORITY_PATTERN = '/^[\/\\\\]{1,2}[a-zA-Z][:|]$/'; protected const WINDOWS_PATH_PATTERN = '/(?:^|\/)([a-zA-Z])[:|]($|[\/#\?].*)/'; protected const WHITESPACE_CHARS = "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x20"; @@ -178,7 +178,7 @@ PCRE; $this->setPort(substr($match[2], 1)); } } - if (!$this->specialScheme && !strlen($match[1])) { + if (!$this->specialScheme && !strlen((string) $this->host)) { throw new \InvalidArgumentException("Credentials with default host in URL"); } } elseif (preg_match(self::HOST_PATTERN, $auth, $match)) { @@ -533,7 +533,7 @@ PCRE; if (!strlen($label)) { $domain[] = $label; } else { - $label = idn_to_ascii($label, \IDNA_NONTRANSITIONAL_TO_ASCII | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ, \INTL_IDNA_VARIANT_UTS46); + $label = idn_to_ascii($label, \IDNA_NONTRANSITIONAL_TO_ASCII | \IDNA_CHECK_BIDI, \INTL_IDNA_VARIANT_UTS46); if ($label === false || idn_to_utf8($label, \IDNA_NONTRANSITIONAL_TO_UNICODE | \IDNA_USE_STD3_RULES, \INTL_IDNA_VARIANT_UTS46) === false) { $domain = false; break; diff --git a/tests/cases/Util/Url/Psr7TestCase.php b/tests/cases/Util/Url/Psr7TestCase.php index 930adf5..7f7576b 100644 --- a/tests/cases/Util/Url/Psr7TestCase.php +++ b/tests/cases/Util/Url/Psr7TestCase.php @@ -443,7 +443,6 @@ abstract class Psr7TestCase extends TestCase { * @dataProvider invalidURI */ public function testCreateFromInvalidUrlKO($uri) { - $this->markTestIncomplete(); $this->expectException(InvalidArgumentException::class); $this->createUri($uri); } diff --git a/tests/cases/Util/Url/UrlTest.php b/tests/cases/Util/Url/UrlTest.php index 93b11fe..59a4bb4 100644 --- a/tests/cases/Util/Url/UrlTest.php +++ b/tests/cases/Util/Url/UrlTest.php @@ -11,6 +11,7 @@ use MensBeam\Lax\Url; /** @covers MensBeam\Lax\Url */ class UrlTest extends Psr7TestCase { private const INCOMPLETE_STD_INPUT = [ + "http://\u{1F}!\"$&'()*+,-.;=_`{|}~/", // PHP's IDNA implementation fails here ]; protected function createUri($uri = '') { @@ -18,7 +19,7 @@ class UrlTest extends Psr7TestCase { } /** @dataProvider provideStandardParsingTests */ - public function xtestParsePerWhatwgRules(string $input, string $base, ?string $exp): void { + public function testParsePerWhatwgRules(string $input, string $base, ?string $exp): void { if (in_array($input, self::INCOMPLETE_STD_INPUT)) { $this->markTestIncomplete(); }