Skip to content

Commit

Permalink
Fix esc() for 'raw' context (#8624)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cleric-K committed Mar 18, 2024
1 parent b8adef6 commit a3e8039
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ function env(string $key, $default = null)
*/
function esc($data, string $context = 'html', ?string $encoding = null)
{
// Provide a way to NOT escape data since
// this could be called automatically by
// the View library.
if ($context === 'raw') {
return $data;
}

if (is_array($data)) {
foreach ($data as &$value) {
$value = esc($value, $context);
Expand All @@ -435,13 +442,6 @@ function esc($data, string $context = 'html', ?string $encoding = null)
if (is_string($data)) {
$context = strtolower($context);

// Provide a way to NOT escape data since
// this could be called automatically by
// the View library.
if ($context === 'raw') {
return $data;
}

if (! in_array($context, ['html', 'js', 'css', 'url', 'attr'], true)) {
throw new InvalidArgumentException('Invalid escape context provided.');
}
Expand Down

0 comments on commit a3e8039

Please sign in to comment.