mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUGFIX #4119: Fixed encoding of readonly TextareaFields and unicode in TextareaFields.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@78732 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
98a75735ee
commit
dedff46bf3
@ -47,7 +47,7 @@ class TextareaField extends FormField {
|
||||
return $this->createTag(
|
||||
'span',
|
||||
$attributes,
|
||||
(($this->value) ? htmlentities($this->value) : '<i>(' . _t('FormField.NONE', 'none') . ')</i>')
|
||||
(($this->value) ? nl2br(htmlentities($this->value, ENT_COMPAT, 'UTF-8')) : '<i>(' . _t('FormField.NONE', 'none') . ')</i>')
|
||||
);
|
||||
} else {
|
||||
$attributes = array(
|
||||
@ -60,7 +60,7 @@ class TextareaField extends FormField {
|
||||
|
||||
if($this->disabled) $attributes['disabled'] = 'disabled';
|
||||
|
||||
return $this->createTag('textarea', $attributes, htmlentities($this->value));
|
||||
return $this->createTag('textarea', $attributes, htmlentities($this->value, ENT_COMPAT, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
|
||||
|
46
tests/forms/TextareaFieldTest.php
Normal file
46
tests/forms/TextareaFieldTest.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
class TextareaFieldTest extends SapphireTest {
|
||||
|
||||
/**
|
||||
* Quick smoke test to ensure that text is being encoded properly.
|
||||
*/
|
||||
function testTextEncoding() {
|
||||
$inputText = "This is my <text>
|
||||
What's on a new-line?
|
||||
These are some unicodes: äöü&<>";
|
||||
|
||||
$field = new TextareaField("Test", "Test", 5, 20);
|
||||
$field->setValue($inputText);
|
||||
|
||||
$this->assertEquals(<<<HTML
|
||||
<textarea id="Test" name="Test" rows="5" cols="20">This is my <text>
|
||||
What's on a new-line?
|
||||
These are some unicodes: äöü&<></textarea>
|
||||
HTML
|
||||
, $field->Field());
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick smoke test to ensure that text is being encoded properly in readonly fields.
|
||||
*/
|
||||
function testReadonlyTextEncoding() {
|
||||
$inputText = "This is my <text>
|
||||
What's on a new-line?
|
||||
These are some unicodes: äöü&<>";
|
||||
|
||||
$field = new TextareaField("Test", "Test", 5, 20);
|
||||
$field = $field->performReadonlyTransformation();
|
||||
|
||||
// Make sure that the field is smart enough to have its value set after being made readonly
|
||||
$field->setValue($inputText);
|
||||
|
||||
$this->assertEquals(<<<HTML
|
||||
<span id="Test" class="readonly" name="Test" readonly="readonly">This is my <text><br />
|
||||
What's on a new-line?<br />
|
||||
These are some unicodes: äöü&<></span>
|
||||
HTML
|
||||
, $field->Field());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user