File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ final class Uri implements UriInterface
4646 public function __construct ($ uri )
4747 {
4848 $ parts = \parse_url ($ uri );
49- if ($ parts === false || (isset ($ parts ['scheme ' ]) && !\preg_match ('#^[a-z]+$#i ' , $ parts ['scheme ' ])) || (isset ($ parts ['host ' ]) && \preg_match ('#[\s_ %+]# ' , $ parts ['host ' ]))) {
49+ if ($ parts === false || (isset ($ parts ['scheme ' ]) && !\preg_match ('#^[a-z]+$#i ' , $ parts ['scheme ' ])) || (isset ($ parts ['host ' ]) && \preg_match ('#[\s %+]# ' , $ parts ['host ' ]))) {
5050 throw new \InvalidArgumentException ('Invalid URI given ' );
5151 }
5252
@@ -164,7 +164,7 @@ public function withHost($host)
164164 return $ this ;
165165 }
166166
167- if (\preg_match ('#[\s_ %+]# ' , $ host ) || ($ host !== '' && \parse_url ('http:// ' . $ host , \PHP_URL_HOST ) !== $ host )) {
167+ if (\preg_match ('#[\s %+]# ' , $ host ) || ($ host !== '' && \parse_url ('http:// ' . $ host , \PHP_URL_HOST ) !== $ host )) {
168168 throw new \InvalidArgumentException ('Invalid URI host given ' );
169169 }
170170
Original file line number Diff line number Diff line change @@ -120,6 +120,9 @@ public static function provideValidUris()
120120 yield [
121121 'http://user%20name:pass%20word@localhost/path%20name?query%20name#frag%20ment '
122122 ];
123+ yield [
124+ 'http://docker_container/ '
125+ ];
123126 }
124127
125128 /**
@@ -329,6 +332,16 @@ public function testWithHostReturnsNewInstanceWhenHostIsChanged()
329332 $ this ->assertEquals ('localhost ' , $ uri ->getHost ());
330333 }
331334
335+ public function testWithHostReturnsNewInstanceWhenHostIsChangedWithUnderscore ()
336+ {
337+ $ uri = new Uri ('http://localhost ' );
338+
339+ $ new = $ uri ->withHost ('docker_container ' );
340+ $ this ->assertNotSame ($ uri , $ new );
341+ $ this ->assertEquals ('docker_container ' , $ new ->getHost ());
342+ $ this ->assertEquals ('localhost ' , $ uri ->getHost ());
343+ }
344+
332345 public function testWithHostReturnsNewInstanceWithHostToLowerCaseWhenHostIsChangedWithUpperCase ()
333346 {
334347 $ uri = new Uri ('http://localhost ' );
You can’t perform that action at this time.
0 commit comments