Skip to content

Commit

Permalink
Don't use FILTER_SANITIZE_STRING for PHP 8.1 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
gmazzap committed Nov 25, 2021
1 parent 6489087 commit e16fa13
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Env/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private function filterString($value): string
throw new \Exception('Invalid scalar.');
}

return (string)filter_var($value, FILTER_SANITIZE_STRING);
return htmlspecialchars(strip_tags((string)$value), ENT_QUOTES, 'UTF-8', false);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/Env/FiltersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function filterDataProvider(): array
[Filters::FILTER_INT, [], null],
[Filters::FILTER_INT, new \ArrayObject(), null],
[Filters::FILTER_STRING, 'hello!', 'hello!'],
[Filters::FILTER_STRING, '<script>alert(\'hi!\')</script>', 'alert(&#39;hi!&#39;)'],
[Filters::FILTER_STRING, '<script>alert(\'hi!\')</script>', 'alert(&#039;hi!&#039;)'],
[Filters::FILTER_STRING, 1, '1'],
[Filters::FILTER_STRING, 123.456, '123.456'],
[Filters::FILTER_STRING, 0, '0'],
Expand Down

0 comments on commit e16fa13

Please sign in to comment.