Skip to content

Commit 2c42bff

Browse files
authored
Allow undescore character in Uri host
I don't understand why this validity check has be added. Has per rfc 2181 (https://datatracker.ietf.org/doc/html/rfc2181#section-11), underscore are valid character to use in an uri host. For my specific usage, it broke for requests using docker internal hostnames.
1 parent 8111281 commit 2c42bff

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Message/Uri.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __construct($uri)
5555
}
5656
// @codeCoverageIgnoreEnd
5757

58-
if ($parts === false || (isset($parts['scheme']) && !\preg_match('#^[a-z]+$#i', $parts['scheme'])) || (isset($parts['host']) && \preg_match('#[\s_%+]#', $parts['host']))) {
58+
if ($parts === false || (isset($parts['scheme']) && !\preg_match('#^[a-z]+$#i', $parts['scheme'])) || (isset($parts['host']) && \preg_match('#[\s%+]#', $parts['host']))) {
5959
throw new \InvalidArgumentException('Invalid URI given');
6060
}
6161

@@ -173,7 +173,7 @@ public function withHost($host)
173173
return $this;
174174
}
175175

176-
if (\preg_match('#[\s_%+]#', $host) || ($host !== '' && \parse_url('http://' . $host, \PHP_URL_HOST) !== $host)) {
176+
if (\preg_match('#[\s%+]#', $host) || ($host !== '' && \parse_url('http://' . $host, \PHP_URL_HOST) !== $host)) {
177177
throw new \InvalidArgumentException('Invalid URI host given');
178178
}
179179

0 commit comments

Comments
 (0)