Skip to content

Commit

Permalink
FIX: Convert newlines to <br /> tags in string fields (fixes #1942)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinglozzer committed May 30, 2013
1 parent 1c7b4a0 commit 4a15845
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions model/fieldtypes/StringField.php
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions tests/model/StringFieldTest.php
Expand Up @@ -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()
Expand Down

0 comments on commit 4a15845

Please sign in to comment.