mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '5.2' into 5
This commit is contained in:
commit
8886a3a93d
3
sake
3
sake
@ -9,7 +9,8 @@ Executes a SilverStripe command"
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -x "$(command -v which)" ]; then
|
command -v which >/dev/null 2>&1
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
echo "Error: sake requires the 'which' command to operate." >&2
|
echo "Error: sake requires the 'which' command to operate." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -192,7 +192,19 @@ class HTMLEditorField extends TextareaField
|
|||||||
*/
|
*/
|
||||||
public function ValueEntities()
|
public function ValueEntities()
|
||||||
{
|
{
|
||||||
return htmlentities($this->Value() ?? '', ENT_COMPAT, 'UTF-8', false);
|
$entities = get_html_translation_table(HTML_ENTITIES);
|
||||||
|
|
||||||
|
foreach ($entities as $key => $value) {
|
||||||
|
$entities[$key] = "/" . $value . "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
$value = preg_replace_callback($entities, function ($matches) {
|
||||||
|
// Don't apply double encoding to ampersand
|
||||||
|
$doubleEncoding = $matches[0] != '&';
|
||||||
|
return htmlentities($matches[0], ENT_COMPAT, 'UTF-8', $doubleEncoding);
|
||||||
|
}, $this->Value() ?? '');
|
||||||
|
|
||||||
|
return $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -171,6 +171,10 @@ class EmbedShortcodeProvider implements ShortcodeHandler
|
|||||||
$arguments['style'] = 'width: ' . intval($arguments['width']) . 'px;';
|
$arguments['style'] = 'width: ' . intval($arguments['width']) . 'px;';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!empty($arguments['caption'])) {
|
||||||
|
$arguments['caption'] = htmlentities($arguments['caption'], ENT_QUOTES, 'UTF-8', false);
|
||||||
|
}
|
||||||
|
|
||||||
// override iframe dimension attributes provided by webservice with ones specified in shortcode arguments
|
// override iframe dimension attributes provided by webservice with ones specified in shortcode arguments
|
||||||
foreach (['width', 'height'] as $attr) {
|
foreach (['width', 'height'] as $attr) {
|
||||||
if (!($value = $arguments[$attr] ?? false)) {
|
if (!($value = $arguments[$attr] ?? false)) {
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
>
|
>
|
||||||
{$Content}
|
{$Content}
|
||||||
<% if $Arguments.caption %>
|
<% if $Arguments.caption %>
|
||||||
<p class="caption">{$Arguments.caption}</p>
|
<p class="caption">{$Arguments.caption.RAW}</p>
|
||||||
<% end_if %>
|
<% end_if %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -75,7 +75,7 @@ class HTMLEditorFieldTest extends FunctionalTest
|
|||||||
$inputText = "These are some unicodes: ä, ö, & ü";
|
$inputText = "These are some unicodes: ä, ö, & ü";
|
||||||
$field = new HTMLEditorField("Test", "Test");
|
$field = new HTMLEditorField("Test", "Test");
|
||||||
$field->setValue($inputText);
|
$field->setValue($inputText);
|
||||||
$this->assertStringContainsString('These are some unicodes: ä, ö, & ü', $field->Field());
|
$this->assertStringContainsString('These are some unicodes: ä, ö, & ü', $field->Field());
|
||||||
// Test shortcodes
|
// Test shortcodes
|
||||||
$inputText = "Shortcode: [file_link id=4]";
|
$inputText = "Shortcode: [file_link id=4]";
|
||||||
$field = new HTMLEditorField("Test", "Test");
|
$field = new HTMLEditorField("Test", "Test");
|
||||||
@ -211,23 +211,34 @@ EOS
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testValueEntities()
|
public function provideTestValueEntities()
|
||||||
{
|
{
|
||||||
$inputText = "The company & partners";
|
return [
|
||||||
$field = new HTMLEditorField("Content");
|
"ampersand" => [
|
||||||
$field->setValue($inputText);
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
"The company & partners",
|
"The company & partners",
|
||||||
$field->obj('ValueEntities')->forTemplate()
|
"The company & partners"
|
||||||
);
|
],
|
||||||
|
"double ampersand" => [
|
||||||
|
"The company &amp; partners",
|
||||||
|
"The company &amp; partners"
|
||||||
|
],
|
||||||
|
"left arrow and right arrow" => [
|
||||||
|
"<p><strong>The company &amp; partners</strong></p>",
|
||||||
|
"<p>&lt;strong&gt;The company &amp; partners&lt;/strong&gt;</p>"
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
$inputText = "The company && partners";
|
/**
|
||||||
|
* @dataProvider provideTestValueEntities
|
||||||
|
*/
|
||||||
|
public function testValueEntities(string $input, string $result)
|
||||||
|
{
|
||||||
$field = new HTMLEditorField("Content");
|
$field = new HTMLEditorField("Content");
|
||||||
$field->setValue($inputText);
|
$field->setValue($input);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
"The company && partners",
|
$result,
|
||||||
$field->obj('ValueEntities')->forTemplate()
|
$field->obj('ValueEntities')->forTemplate()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user