about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-26 17:44:13 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-26 17:44:13 +0300
commit96299844c2e630a8ea27d86d53aadf98216b9ab8 (patch)
tree410d76eb9004c783545ee80129c69096b2040752
parente3b4fbde9066ec58873240ff67c7fb7ce1dfbdd4 (diff)
downloadthe-epube-96299844c2e630a8ea27d86d53aadf98216b9ab8.tar.gz
the-epube-96299844c2e630a8ea27d86d53aadf98216b9ab8.tar.xz
drop clean()
-rw-r--r--classes/Request.php26
-rw-r--r--include/common.php13
-rw-r--r--tests/RequestTest.php13
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