diff options
| author | fox <fox@fakecake.org> | 2026-06-26 17:47:01 +0300 |
|---|---|---|
| committer | fox <fox@fakecake.org> | 2026-06-26 17:47:01 +0300 |
| commit | 04524943b6b6b1ed314df320630fa3eed1783b2c (patch) | |
| tree | 410d76eb9004c783545ee80129c69096b2040752 | |
| parent | a17d0f6277cd169f237ce8bb5cfc705c5582ed66 (diff) | |
| parent | 96299844c2e630a8ea27d86d53aadf98216b9ab8 (diff) | |
| download | the-epube-04524943b6b6b1ed314df320630fa3eed1783b2c.tar.gz the-epube-04524943b6b6b1ed314df320630fa3eed1783b2c.tar.xz | |
Merge branch 'dev' into 'master'
drop clean() See merge request git/the-epube!69
| -rw-r--r-- | classes/Request.php | 26 | ||||
| -rw-r--r-- | include/common.php | 13 | ||||
| -rw-r--r-- | tests/RequestTest.php | 13 |
3 files changed, 21 insertions, 31 deletions
diff --git a/classes/Request.php b/classes/Request.php index 3a8e696..cd7cbe8 100644 --- a/classes/Request.php +++ b/classes/Request.php @@ -3,7 +3,7 @@ * Typed parameter extraction wrapper around PHP superglobals. * * Provides clean, type-safe access to request parameters, replacing the - * repetitive clean($_REQUEST['key'] ?? default) pattern throughout handlers. + * repetitive $_REQUEST['key'] ?? default pattern throughout handlers. * * Usage: * $request = new Request(); @@ -131,11 +131,11 @@ class Request { if ($value === null) { return $default; } - return clean((string)$value); + return trim((string)$value); } /** - * Get a sanitized integer value. + * Get an integer value. * * @param string $key * @param int $default @@ -146,11 +146,11 @@ class Request { if ($value === null) { return $default; } - return (int) clean((string)$value); + return (int) $value; } /** - * Get a sanitized float value. + * Get a float value. * * @param string $key * @param float $default @@ -161,7 +161,7 @@ class Request { if ($value === null) { return $default; } - return (float) clean((string)$value); + return (float) $value; } /** @@ -186,7 +186,7 @@ class Request { * Get a sanitized array value. * * If the value is a comma-separated string, it will be split into an array. - * Each element is trimmed and HTML tags are stripped. + * Each element is trimmed. * * @param string $key * @param array<int|string, mixed> $default @@ -199,16 +199,16 @@ class Request { } if (is_array($value)) { - return clean($value); + return array_map(static fn($v) => is_string($v) ? trim((string)$v) : $v, $value); } // Handle comma-separated string values - $cleaned = clean((string)$value); - if ($cleaned === '') { + $trimmed = trim((string)$value); + if ($trimmed === '') { return []; } - return array_map('trim', explode(',', $cleaned)); + return array_map('trim', explode(',', $trimmed)); } /** @@ -349,7 +349,9 @@ class Request { * @return bool */ public static function _to_bool(mixed $value): bool { - $value = clean($value); + if (is_string($value)) { + $value = trim($value); + } if (is_bool($value)) { return $value; diff --git a/include/common.php b/include/common.php index 684d9c6..12753c8 100644 --- a/include/common.php +++ b/include/common.php @@ -32,16 +32,3 @@ return ""; } - - /** - * This is used for user http parameters unless HTML code is actually needed. - */ - function clean(mixed $param): mixed { - if (is_array($param)) { - return array_map("trim", array_map("strip_tags", $param)); - } else if (is_string($param)) { - return trim(strip_tags($param)); - } else { - return $param; - } - } diff --git a/tests/RequestTest.php b/tests/RequestTest.php index fc7ff97..082e06b 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -266,11 +266,11 @@ final class RequestTest extends TestCase $this->assertEquals('default', $request->getString('missing', 'default')); } - public function test_get_string_sanitizes_input(): void + public function test_get_string_trims_whitespace(): void { - $_REQUEST = ['html' => '<script>alert(1)</script>']; + $_REQUEST = ['text' => ' hello world ']; $request = new Request(); - $this->assertEquals('alert(1)', $request->getString('html')); + $this->assertEquals('hello world', $request->getString('text')); } public function test_get_string_handles_numeric_value(): void @@ -633,10 +633,11 @@ final class RequestTest extends TestCase $this->assertFalse(Request::_to_bool(null)); } - public function test_to_bool_handles_sanitization(): void + public function test_to_bool_rejects_non_boolean_strings(): void { - // clean() strips tags; '<script>1</script>' → '1' → true - $this->assertTrue(Request::_to_bool('<script>1</script>')); + // Strings that aren't recognized boolean keywords evaluate to false, + // since we no longer attempt HTML stripping. + $this->assertFalse(Request::_to_bool('<script>1</script>')); } public function test_to_bool_case_insensitive(): void |
