Skip to content

Commit

Permalink
Fix escape for non-string data
Browse files Browse the repository at this point in the history
  • Loading branch information
sharifzadesina committed Sep 1, 2023
1 parent 982658c commit 8ff4bc5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
20 changes: 16 additions & 4 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,28 @@ protected function isColumnRequired($name)
}

/**
* Indicates if the column should be escaped.
* Indicates if the column is a raw column, raw columns should be inacted in either way.
*
* @param string $name
* @return bool
*/
protected function shouldEscapeColumn($name)
protected function isColumnRaw($name)
{
return !in_array($name, $this->raw);
}

/**
* Indicates if the column should be escaped.
*
* @param string $name
* @param mixed $value
* @return bool
*/
protected function shouldEscapeColumn($name, $value)
{
return is_string($value) && $this->isColumnRaw($name);
}

/**
* Sets up the source columns at the row.
*
Expand All @@ -131,7 +143,7 @@ protected function setupSourceColumns(&$row, $record)

foreach ($columns as $name => $value) {
if ($this->isColumnRequired($name)) {
Arr::set($row, $name, $this->shouldEscapeColumn($name) ? e($value) : $value);
Arr::set($row, $name, $this->shouldEscapeColumn($name, $value) ? e($value) : $value);
}
}
}
Expand All @@ -146,7 +158,7 @@ protected function setupAddonColumns(&$row, $record)
{
foreach ($this->addon as $name => $data) {
if ($this->isColumnRequired($name)) {
Arr::set($row, $name, Helper::resolveData($data, compact('record'), $this->shouldEscapeColumn($name)));
Arr::set($row, $name, Helper::resolveData($data, compact('record'), $this->isColumnRaw($name)));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Support/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public static function resolveData($data, array $params = [], $escape = true)
// NOTE: $params does include keys and variable names, but for methods, we don't want to use PHP 8 named arguments, so we just use array_values to fix the problem
$data = call_user_func_array($data, array_values($params));
}
// No need to escape blade data, so just return the content
else {
// No need to escape blade data, so just return the content
return static::resolveBladeData($data, $params);
}

if ($escape) {
if ($escape and is_string($data)) {
return e($data);
} else {
return $data;
Expand Down

0 comments on commit 8ff4bc5

Please sign in to comment.