@@ -338,40 +338,45 @@ public static function normalizeAuthority(Stringable|string $authority): string
338338 */
339339 public static function resolve (Stringable |string $ uri , Stringable |string |null $ baseUri = null ): string
340340 {
341+ $ uri = (string ) $ uri ;
341342 if ('' === $ uri ) {
342343 $ uri = $ baseUri ?? throw new SyntaxError ('The uri can not be the empty string when there \'s no base URI. ' );
343344 }
344345
345- $ uri = self ::parse ($ uri );
346- $ baseUri = null !== $ baseUri ? self ::parse ($ baseUri ) : $ uri ;
347- if (null === $ baseUri ['scheme ' ]) {
346+ $ uriComponents = self ::parse ($ uri );
347+ $ baseUriComponents = $ uriComponents ;
348+ if (null !== $ baseUri && (string ) $ uri !== (string ) $ baseUri ) {
349+ $ baseUriComponents = self ::parse ($ baseUri );
350+ }
351+
352+ if (null === $ baseUriComponents ['scheme ' ]) {
348353 throw new SyntaxError ('The base URI must be an absolute URI or null; If the base URI is null the URI must be an absolute URI. ' );
349354 }
350355
351- if (null !== $ uri ['scheme ' ] && '' !== $ uri ['scheme ' ]) {
352- $ uri ['path ' ] = self ::removeDotSegments ($ uri ['path ' ]);
356+ if (null !== $ uriComponents ['scheme ' ] && '' !== $ uriComponents ['scheme ' ]) {
357+ $ uriComponents ['path ' ] = self ::removeDotSegments ($ uriComponents ['path ' ]);
353358
354- return UriString::build ($ uri );
359+ return UriString::build ($ uriComponents );
355360 }
356361
357- if (null !== self ::buildAuthority ($ uri )) {
358- $ uri ['scheme ' ] = $ baseUri ['scheme ' ];
359- $ uri ['path ' ] = self ::removeDotSegments ($ uri ['path ' ]);
362+ if (null !== self ::buildAuthority ($ uriComponents )) {
363+ $ uriComponents ['scheme ' ] = $ baseUriComponents ['scheme ' ];
364+ $ uriComponents ['path ' ] = self ::removeDotSegments ($ uriComponents ['path ' ]);
360365
361- return UriString::build ($ uri );
366+ return UriString::build ($ uriComponents );
362367 }
363368
364- [$ path , $ query ] = self ::resolvePathAndQuery ($ uri , $ baseUri );
369+ [$ path , $ query ] = self ::resolvePathAndQuery ($ uriComponents , $ baseUriComponents );
365370 $ path = UriString::removeDotSegments ($ path );
366- if ('' !== $ path && '/ ' !== $ path [0 ] && null !== self ::buildAuthority ($ baseUri )) {
371+ if ('' !== $ path && '/ ' !== $ path [0 ] && null !== self ::buildAuthority ($ baseUriComponents )) {
367372 $ path = '/ ' .$ path ;
368373 }
369374
370- $ baseUri ['path ' ] = $ path ;
371- $ baseUri ['query ' ] = $ query ;
372- $ baseUri ['fragment ' ] = $ uri ['fragment ' ];
375+ $ baseUriComponents ['path ' ] = $ path ;
376+ $ baseUriComponents ['query ' ] = $ query ;
377+ $ baseUriComponents ['fragment ' ] = $ uriComponents ['fragment ' ];
373378
374- return UriString::build ($ baseUri );
379+ return UriString::build ($ baseUriComponents );
375380 }
376381
377382 /**
0 commit comments