Skip to content

Commit bc5ad56

Browse files
committed
Don't add a file:// prefix to URI that already have a scheme (jsonrainbow#455)
Some URI types do not pass validation against \FILTER_VAR_URL (e.g. phar://), but are still valid and still have a scheme. This patch catches those situations via a simple regex.
1 parent 7ccb0e6 commit bc5ad56

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/JsonSchema/Uri/UriResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ public function generate(array $components)
7777
public function resolve($uri, $baseUri = null)
7878
{
7979
// treat non-uri base as local file path
80-
if (!is_null($baseUri) && !filter_var($baseUri, \FILTER_VALIDATE_URL)) {
80+
if (
81+
!is_null($baseUri) &&
82+
!filter_var($baseUri, \FILTER_VALIDATE_URL) &&
83+
!preg_match('|^[^/]+://|u', $baseUri)
84+
) {
8185
if (is_file($baseUri)) {
8286
$baseUri = 'file://' . realpath($baseUri);
8387
} elseif (is_dir($baseUri)) {

0 commit comments

Comments
 (0)