Skip to content

Commit

Permalink
Merge pull request mautic#12621 from kuzmany/fix-form_autofil_email_f…
Browse files Browse the repository at this point in the history
…ield_issue_if_email_contains_a

Fix form autofill email field issue if email contains a +
  • Loading branch information
escopecz authored Jan 31, 2024
2 parents 7aeca7d + 2c9ba96 commit 8f32d14
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/bundles/FormBundle/Helper/FormFieldHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public function populateField($field, $value, $formName, &$formHtml): void
public function sanitizeValue($value)
{
$valueType = gettype($value);
$value = str_replace(['"', '>', '<'], ['&quot;', '&gt;', '&lt;'], strip_tags(urldecode($value)));
$value = str_replace(['"', '>', '<'], ['&quot;', '&gt;', '&lt;'], strip_tags(rawurldecode($value)));
// for boolean expect 0 or 1
if ('boolean' === $valueType) {
return (int) $value;
Expand Down
29 changes: 29 additions & 0 deletions app/bundles/FormBundle/Tests/Model/FormModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,35 @@ public function testPopulateValuesWithLead(): void
$this->formModel->populateValuesWithLead($form, $formHtml);
}

public function testPopulateValuesWithLeadWithSuffixEMail(): void
{
$formHtml = '<html>';
$form = new Form();
$emailField = new Field();
$contact = new Lead();

$emailField->setMappedField('email');
$emailField->setMappedObject('contact');
$emailField->setIsAutoFill(true);
$form->addField(123, $emailField);

$contactCompanyData = [
'email' => '[email protected]',
];

$this->contactTracker->method('getContact')
->willReturn($contact);

$this->primaryCompanyHelper->method('getProfileFieldsWithPrimaryCompany')
->willReturn($contactCompanyData);

$this->fieldHelper->expects($this->once())
->method('populateField')
->with($emailField, '[email protected]', 'form-', $formHtml);

$this->formModel->populateValuesWithLead($form, $formHtml);
}

public function testPopulateValuesWithCompany(): void
{
$formHtml = '<html>';
Expand Down

0 comments on commit 8f32d14

Please sign in to comment.