Skip to content

Commit

Permalink
Fix: Escape double quotes in emailTemplateOptions (#6938)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjohnson authored Sep 14, 2023
1 parent d5d51a2 commit e07af08
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/DonationForms/Properties/FormSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,9 @@ public static function fromArray(array $array): self
*/
public static function fromJson(string $json): self
{
$self = new self();
$array = json_decode($json, true);

return $self::fromArray($array);
return self::fromArray(
json_decode($json, true)
);
}

/**
Expand All @@ -258,8 +257,16 @@ public function toJson($options = 0): string
$this->toArray(),
[
'goalType' => $this->goalType ? $this->goalType->getValue() : null,
'emailTemplateOptions' => array_map([$this, 'addSlashesRecursive'], $this->emailTemplateOptions),
]
)
);
}

public function addSlashesRecursive($value)
{
return is_array($value)
? array_map([$this, 'addSlashesRecursive'], $value)
: addslashes($value);
}
}
33 changes: 33 additions & 0 deletions tests/Unit/DonationForms/Properties/FormSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Give\Tests\Unit\DonationForms\Properties;

use Give\DonationForms\Properties\FormSettings;
use Give\Tests\TestCase;

final class FormSettingsTest extends TestCase
{
public function testAddSlashesRecursive()
{
$array = [
'one' => [
'aye' => 'This is "a" test',
'bee' => [
'see' => 'This is "another" test',
]
]
];

$this->assertEquals(
[
'one' => [
'aye' => 'This is \"a\" test',
'bee' => [
'see' => 'This is \"another\" test',
]
]
],
(new FormSettings)->addSlashesRecursive($array)
);
}
}

0 comments on commit e07af08

Please sign in to comment.