Skip to content

Commit

Permalink
FIX Multi HTML entities in shortcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sabina Talipova committed Aug 8, 2023
1 parent 2a56cc3 commit 37d2ebb
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Forms/HTMLEditor/HTMLEditorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,14 @@ public function getSchemaStateDefaults()
$stateDefaults['data'] = $config->getConfigSchemaData();
return $stateDefaults;
}

/**
* Return value with all values encoded in html entities
*
* @return string Raw HTML
*/
public function ValueEntities()
{
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8', false);
}
}
21 changes: 21 additions & 0 deletions tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,25 @@ public function testReadonlyField()
$readonlyContent->getValue()
);
}

public function testValueEntities()
{
$inputText = "The company & partners";
$field = new HTMLEditorField("Content");
$field->setValue($inputText);

$this->assertEquals(
"The company & partners",
$field->obj('ValueEntities')->forTemplate()
);

$inputText = "The company && partners";
$field = new HTMLEditorField("Content");
$field->setValue($inputText);

$this->assertEquals(
"The company && partners",
$field->obj('ValueEntities')->forTemplate()
);
}
}
18 changes: 18 additions & 0 deletions tests/php/Forms/TextareaFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,23 @@ public function testValueEntities()
false,
$field->obj('ValueEntities')->getProcessShortcodes()
);

$inputText = "To escape an ampersand in HTML, use &";
$field = new TextareaField("Test", "Test");
$field->setValue($inputText);

$this->assertEquals(
"To escape an ampersand in HTML, use &",
$field->obj('ValueEntities')->forTemplate()
);

$inputText = "The symbol of ampersand is &";
$field = new TextareaField("Test", "Test");
$field->setValue($inputText);

$this->assertEquals(
"The symbol of ampersand is &",
$field->obj('ValueEntities')->forTemplate()
);
}
}

0 comments on commit 37d2ebb

Please sign in to comment.