Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Support pre tag #11253

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Forms/HTMLEditor/HTMLEditorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ public function getSchemaStateDefaults()
*/
public function ValueEntities()
{
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8', false);
$value = htmlentities($this->Value(), ENT_COMPAT, 'UTF-8', false);

$value = preg_replace_callback('/(?:&lt;pre.*?&gt;(?<replace>.*?)&lt;\/pre&gt;)/imsu', function ($matches) {
return str_replace($matches['replace'], htmlentities($matches['replace'], ENT_COMPAT, 'UTF-8', true), $matches[0]);
}, $value);

return $value;
}

/**
Expand Down
35 changes: 23 additions & 12 deletions tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,34 @@ public function testReadonlyField()
);
}

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

$this->assertEquals(
"The company &amp; partners",
$field->obj('ValueEntities')->forTemplate()
);
return [
"ampersand" => [
"The company &amp; partners",
"The company &amp; partners"
],
"double ampersand" => [
"The company &amp;amp; partners",
"The company &amp;amp; partners"
],
"left arrow and right arrow" => [
"<p><pre>&lt;strong&gt;The company and partners&lt;/strong&gt;</pre></p>",
"&lt;p&gt;&lt;pre&gt;&amp;lt;strong&amp;gt;The company and partners&amp;lt;/strong&amp;gt;&lt;/pre&gt;&lt;/p&gt;"
],
];
}

$inputText = "The company &amp;&amp; partners";
/**
* @dataProvider provideTestValueEntities
*/
public function testValueEntities(string $input, string $result)
{
$field = new HTMLEditorField("Content");
$field->setValue($inputText);
$field->setValue($input);

$this->assertEquals(
"The company &amp;&amp; partners",
$result,
$field->obj('ValueEntities')->forTemplate()
);
}
Expand Down
Loading