diff --git a/docs/en/04_Changelogs/3.4.0.md b/docs/en/04_Changelogs/3.4.0.md new file mode 100644 index 000000000..8d5926046 --- /dev/null +++ b/docs/en/04_Changelogs/3.4.0.md @@ -0,0 +1,16 @@ +# 3.4.0 (unreleased) + +## Upgrading notes + +Upgrading from 3.3 to 3.4 shouldn't require any code changes. + +Note that if you are upgrading from 3.1, you should review the [3.2 upgrade notes](3.2.0). + +### Other changes to be aware of + +These changes are unlikely to affect your upgrade, but we've noted them just in case you had unusual project code that +was affected by these: + + * When FormFields are rendered, leading & trailing whitespace is now stripped. The resulting HTML for form fields is + the same for the default fields, but if you have a custom form field that is relying on trailing whitespace being + outputted. diff --git a/forms/FormField.php b/forms/FormField.php index eab6bcca0..722a3fcaf 100644 --- a/forms/FormField.php +++ b/forms/FormField.php @@ -839,7 +839,16 @@ class FormField extends RequestHandler { $this->extend('onBeforeRender', $this); - return $context->renderWith($this->getTemplates()); + $result = $context->renderWith($this->getTemplates()); + + // Trim whitespace from the result, so that trailing newlines are supressed. Works for strings and HTMLText values + if(is_string($result)) { + $result = trim($result); + } else if($result instanceof DBField) { + $result->setValue(trim($result->getValue())); + } + + return $result; } /** diff --git a/tests/view/SSViewerTest.php b/tests/view/SSViewerTest.php index 45cbf4e69..bb4cd7c44 100644 --- a/tests/view/SSViewerTest.php +++ b/tests/view/SSViewerTest.php @@ -134,7 +134,7 @@ class SSViewerTest extends SapphireTest { public function render($templateString, $data = null, $cacheTemplate = false) { $t = SSViewer::fromString($templateString, $cacheTemplate); if(!$data) $data = new SSViewerTestFixture(); - return $t->process($data); + return trim(''.$t->process($data)); } public function testRequirements() { @@ -1095,10 +1095,10 @@ after') $this->useTestTheme(dirname(__FILE__), 'layouttest', function() use ($self) { $template = new SSViewer(array('Page')); - $self->assertEquals('Foo', $template->process(new ArrayData(array()))); + $self->assertEquals("Foo\n\n", $template->process(new ArrayData(array()))); $template = new SSViewer(array('Shortcodes', 'Page')); - $self->assertEquals('[file_link]', $template->process(new ArrayData(array()))); + $self->assertEquals("[file_link]\n\n", $template->process(new ArrayData(array()))); }); }