Skip to content

Commit

Permalink
esc() for 'raw' context (Fixes #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 88ec458
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,22 +426,22 @@ function env(string $key, $default = null)
*/
function esc($data, string $context = 'html', ?string $encoding = null)
{
$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 (is_array($data)) {
foreach ($data as &$value) {
$value = esc($value, $context);
}
}

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 88ec458

Please sign in to comment.