Permalink
Browse files

FIX: Convert newlines to <br /> tags in string fields (fixes #1942)

  • Loading branch information...
1 parent 1c7b4a0 commit 4a158454d68d84a50f0c06ba1e8780bb64989ca5 @kinglozzer kinglozzer committed May 30, 2013
Showing with 17 additions and 0 deletions.
  1. +7 −0 model/fieldtypes/StringField.php
  2. +10 −0 tests/model/StringFieldTest.php
View
7 model/fieldtypes/StringField.php
@@ -96,6 +96,13 @@ public function prepValueForDB($value) {
return parent::prepValueForDB($value);
}
}
+
+ /**
+ * @return string
+ */
+ public function forTemplate() {
+ return nl2br($this->XML());
+ }
/**
* Limit this field's content by a number of characters.
View
10 tests/model/StringFieldTest.php
@@ -5,6 +5,16 @@
*/
class StringFieldTest extends SapphireTest {
+
+ /**
+ * @covers StringField->forTemplate()
+ */
+ public function testForTemplate() {
+ $this->assertEquals(
+ "this is<br />\na test!",
+ DBField::create_field('StringFieldTest_MyStringField', "this is\na test!")->forTemplate()
+ );
+ }
/**
* @covers StringField->LowerCase()

0 comments on commit 4a15845

Please sign in to comment.