BUG Fix <form > tag being invalidly nested inside <p> tag

This commit is contained in:
Damian Mooyman 2015-08-19 14:22:03 +12:00
parent 52072d44eb
commit 09553a1293
3 changed files with 18 additions and 1 deletions

View File

@ -342,7 +342,7 @@ class UserDefinedForm_Controller extends Page_Controller {
if($this->Content && $form = $this->Form()) {
$hasLocation = stristr($this->Content, '$UserDefinedForm');
if($hasLocation) {
$content = str_ireplace('$UserDefinedForm', $form->forTemplate(), $this->Content);
$content = preg_replace('/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content);
return array(
'Content' => DBField::create_field('HTMLText', $content),
'Form' => ""

View File

@ -353,4 +353,20 @@ class UserDefinedFormTest extends FunctionalTest {
$result4
);
}
public function testIndex() {
// Test that the $UserDefinedForm is stripped out
$page = $this->objFromFixture('UserDefinedForm', 'basic-form-page');
$page->publish('Stage', 'Live');
$result = $this->get($page->Link());
$body = Convert::nl2os($result->getBody(), ''); // strip out newlines
$this->assertFalse($result->isError());
$this->assertContains('<p>Here is my form</p><form', $body);
$this->assertContains('</form><p>Thank you for filling it out</p>', $body);
$this->assertNotContains('<p>$UserDefinedForm</p>', $body);
$this->assertNotContains('<p></p>', $body);
$this->assertNotContains('</p><p>Thank you for filling it out</p>', $body);
}
}

View File

@ -204,6 +204,7 @@ UserDefinedForm_EmailRecipient:
UserDefinedForm:
basic-form-page:
Content: '<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>'
Title: User Defined Form
Fields: =>EditableFormStep.form1step1,=>EditableTextField.basic-text
EmailRecipients: =>UserDefinedForm_EmailRecipient.recipient-1, =>UserDefinedForm_EmailRecipient.no-html, =>UserDefinedForm_EmailRecipient.no-data