diff --git a/README.md b/README.md index 03837d69..ca5cee61 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,11 @@ docker exec -it gcms-cloudflareonion bash # Complete the creation of your environment (if it doesn't happen automagically) docker exec -it gcms-cloudflareonion "/docker-entrypoint.sh" + +# Running tests +composer run-tests --working-dir=./wp-content/plugins/ ``` + Visit: http://127.0.0.1:8081 diff --git a/src/Controllers/Admin/CacheClearancePage.php b/src/Controllers/Admin/CacheClearancePage.php index d7388b90..340f63f1 100644 --- a/src/Controllers/Admin/CacheClearancePage.php +++ b/src/Controllers/Admin/CacheClearancePage.php @@ -119,7 +119,7 @@ public function handleFormSubmission($input) add_settings_error( 'field_path_validator', 'invalid_paths', - "Sending '${url}' to Cloudflare for clearance", + "Sending '{$url}' to Cloudflare for clearance", 'warning' ); diff --git a/src/Utils/functions.php b/src/Utils/functions.php index 6d36a3c4..1140edbb 100644 --- a/src/Utils/functions.php +++ b/src/Utils/functions.php @@ -31,12 +31,7 @@ function isValidUrlPath($path) { } // Check for invalid URL path characters - if (preg_match('/[<>"\{\}\|\\\^\[\]`]/', $decoded)) { - return false; - } - - // Reject non ascii characters - if (preg_match('/[^\x01-\x7F]/', $decoded)) { + elseif (preg_match('/[<>"\{\}\|\\\^\[\]`]/', $decoded)) { return false; } diff --git a/tests/phpunit/Utils/FunctionsTest.php b/tests/phpunit/Utils/FunctionsTest.php index 5ddbda6f..4a39a1d4 100644 --- a/tests/phpunit/Utils/FunctionsTest.php +++ b/tests/phpunit/Utils/FunctionsTest.php @@ -70,7 +70,7 @@ public static function invalidPathsProvider(): array '/[claude]/m/a/b/c', false ], - 'Paths with invalid characters are not accepted' => [ + 'Paths with invalid characters are not accepted [2]' => [ '/{claude}/<>/a/b/c', false ], @@ -85,4 +85,64 @@ public function testInvalidUrlPaths(string $input, bool $expected): void $url = isValidUrlPath($input); $this->assertEquals($url, $expected); } + + + //======================= + //======================= + //======================= + + public static function isValidPathProvider(): array + { + return [ + 'Accept encoded path' => [ + '/ko-kr/range/%EB%B0%9C%EB%A0%8C%ED%83%80%EC%9D%B87%EB%85%84-%EB%B2%84%EB%B2%88%ED%94%BC%EB%8B%88%EC%89%AC/', + true + ], + 'Must start with /' => [ + '/hello/world/', + true + ], + 'Must start with / [2]' => [ + 'hello/world/', + false + ], + 'Accept non latin paths' => [ + '/zh-cn/条款和条件/', + true + ], + 'Accept non latin paths [2]' => [ + '/zh-cn/إسرائيل/', + true + ], + 'Reject invalid url path' => [ + '/zh-cn/', + false + ], + 'Accept path with non ascii characters' => [ + '/en/AC/Ææ½⅓¼⅕⅙⅐⅛⅑/', + true + ], + 'Accept path with non ascii characters [2]' => [ + '/en/Düsseldorf/Köln-Москва-!@#$/', + true + ], + 'Reject full urls' => [ + 'http://www.test.com/my-path/hello', + false + ], + 'Reject full urls [2]' => [ + 'https://test.com/my-path/hello', + false + ] + ]; + } + + /** + * @dataProvider isValidPathProvider + */ + public function testPathIsValid(string $input, bool $expected): void + { + $check = isValidUrlPath($input); + $this->assertEquals($check, $expected); + } }