Browse Source

Fix TypeError.

Closes #15494
ADmad 5 years ago
parent
commit
8a82b0e085
2 changed files with 8 additions and 3 deletions
  1. 5 3
      src/Routing/Asset.php
  2. 3 0
      tests/TestCase/Routing/AssetTest.php

+ 5 - 3
src/Routing/Asset.php

@@ -214,13 +214,15 @@ class Asset
     protected static function encodeUrl(string $url): string
     {
         $path = parse_url($url, PHP_URL_PATH);
+        if ($path === false) {
+            $path = $url;
+        }
+
         $parts = array_map('rawurldecode', explode('/', $path));
         $parts = array_map('rawurlencode', $parts);
         $encoded = implode('/', $parts);
 
-        $url = str_replace($path, $encoded, $url);
-
-        return $url;
+        return str_replace($path, $encoded, $url);
     }
 
     /**

+ 3 - 0
tests/TestCase/Routing/AssetTest.php

@@ -136,6 +136,9 @@ class AssetTest extends TestCase
         // URL encoding is done
         $result = Asset::url('dir/big+tall/image', ['ext' => '.jpg']);
         $this->assertSame('/dir/big%2Btall/image.jpg', $result);
+
+        $result = Asset::url('/posts/index/adbirawwy/page:6/sort:type/');
+        $this->assertSame('/posts/index/adbirawwy/page%3A6/sort%3Atype/', $result);
     }
 
     /**