From 09553a129355ad8c348be5fff7d0dcbe5292ddce Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Wed, 19 Aug 2015 14:22:03 +1200 Subject: [PATCH] BUG Fix
tag being invalidly nested inside

tag --- code/model/UserDefinedForm.php | 2 +- tests/UserDefinedFormTest.php | 16 ++++++++++++++++ tests/UserDefinedFormTest.yml | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/code/model/UserDefinedForm.php b/code/model/UserDefinedForm.php index 32b310a..f2fcb26 100755 --- a/code/model/UserDefinedForm.php +++ b/code/model/UserDefinedForm.php @@ -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('/(]*>)?\\$UserDefinedForm(<\\/p>)?/i', $form->forTemplate(), $this->Content); return array( 'Content' => DBField::create_field('HTMLText', $content), 'Form' => "" diff --git a/tests/UserDefinedFormTest.php b/tests/UserDefinedFormTest.php index 4123f09..5ba2c8a 100644 --- a/tests/UserDefinedFormTest.php +++ b/tests/UserDefinedFormTest.php @@ -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('

Here is my form

assertContains('

Thank you for filling it out

', $body); + + $this->assertNotContains('

$UserDefinedForm

', $body); + $this->assertNotContains('

', $body); + $this->assertNotContains('

Thank you for filling it out

', $body); + } } \ No newline at end of file diff --git a/tests/UserDefinedFormTest.yml b/tests/UserDefinedFormTest.yml index 9decd15..d4efbe1 100644 --- a/tests/UserDefinedFormTest.yml +++ b/tests/UserDefinedFormTest.yml @@ -204,6 +204,7 @@ UserDefinedForm_EmailRecipient: UserDefinedForm: basic-form-page: + Content: '

Here is my form

$UserDefinedForm

Thank you for filling it out

' Title: User Defined Form Fields: =>EditableFormStep.form1step1,=>EditableTextField.basic-text EmailRecipients: =>UserDefinedForm_EmailRecipient.recipient-1, =>UserDefinedForm_EmailRecipient.no-html, =>UserDefinedForm_EmailRecipient.no-data