Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion src/Controllers/Admin/CacheClearancePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);

Expand Down
7 changes: 1 addition & 6 deletions src/Utils/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
62 changes: 61 additions & 1 deletion tests/phpunit/Utils/FunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
Expand All @@ -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/<hello></hello>',
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);
}
}