You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
URIs are universal. I assumed that the implementation of Uri object would be too.
TLDR; The following snippet produces InvalidArgumentException: Uri scheme must be one of: "", "http", "https" exception because of scheme filtering in Uri::filterScheme.
I tried using Slim/Psr7 for handling generic URIs that I'm using for DSN-style configuration variables.
There are plenty of valid schemes, so setting Uri::SUPPORTED_SCHEMES is impractical for this purpose.
Now, Guzzle handles this correctly, as does the native parse_url function.
useGuzzleHttp\Psr7\Uri;
useSlim\Psr7\Factory\UriFactory;
$uri = 'smtp://smtp.dakujem.dev:25';
// tel:+1-816-555-1212// ftp://ftp.is.co.za/rfc/rfc1808.txt// ldap://[2001:db8::7]/c=GB?objectClass?one
(string)(newUri($uri));
// InvalidArgumentException: Uri scheme must be one of: "", "http", "https"
(string)(newUriFactory())->createUri($uri); // exception here
Suggested solution
I suggest using opt-in approach: keep Slim/Psr7 universal and activate the filter when booting Slim framework.
publicconstSUPPORTED_SCHEMES = null; // initialize the class constant with null// within filterScheme methodif (static::SUPPORTED_SCHEMES !== null && !key_exists($scheme, static::SUPPORTED_SCHEMES)) {
thrownewInvalidArgumentException( ... );
}
// and somewhere in Slim bootstrapping phaseUri::SUPPORTED_SCHEMES = ['', 'http', 'https'];
I believe you get the idea.
This might be related to other parts of the Uri object, in particular the other filter* methods.
The text was updated successfully, but these errors were encountered:
dakujem
changed the title
Construction of Uri via UriFactory fails for non-HTTP related URIs
Construction of Uri via UriFactory fails for non-HTTP-related URIs
Mar 10, 2023
URIs are universal. I assumed that the implementation of
Uri
object would be too.TLDR; The following snippet produces
InvalidArgumentException: Uri scheme must be one of: "", "http", "https"
exception because of scheme filtering inUri::filterScheme
.Reasoning
I tried using Slim/Psr7 for handling generic URIs that I'm using for DSN-style configuration variables.
There are plenty of valid schemes, so setting
Uri::SUPPORTED_SCHEMES
is impractical for this purpose.Now, Guzzle handles this correctly, as does the native
parse_url
function.Suggested solution
I suggest using opt-in approach: keep Slim/Psr7 universal and activate the filter when booting Slim framework.
I believe you get the idea.
The text was updated successfully, but these errors were encountered: