Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion classes/helpers/FrmSpamEntriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ public static function escape_value( $value ) {
return array_map( array( self::class, 'escape_value' ), $value );
}

return is_string( $value ) ? esc_html( $value ) : $value;
return is_string( $value ) ? esc_html( str_replace( array( '<br>', '<br/>', '<br />' ), "\n", $value ) ) : $value;
}

/**
Expand Down
52 changes: 52 additions & 0 deletions tests/phpunit/misc/test_FrmSpamOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,58 @@
* @covers FrmFieldValue
*/
class test_FrmSpamOutput extends FrmUnitTest {
/**
* Spam values retain line breaks while other submitted markup remains escaped.
*/
public function test_escape_value_preserves_line_breaks_and_escapes_markup() {
$value = array( 'nested' => array( 'First<br>Second<br/>Third<br />Fourth<img src=x onerror=alert(1)>', '', null, 0 ) );
$expected = array( 'nested' => array( "First\nSecond\nThird\nFourth&lt;img src=x onerror=alert(1)&gt;", '', null, 0 ) );

$this->assertSame( $expected, FrmSpamEntriesHelper::escape_value( $value ), 'Breaks should become newlines without allowing other markup or changing non-string values.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmSpamOutput::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

/**
* Address formatting remains readable in the entry table after marking an entry as spam.
*/
public function test_spam_address_displays_line_breaks_in_entry_table() {
$form = $this->factory->form->create();
$field = $this->factory->field->create_and_get(
array(
'form_id' => $form,
'type' => 'address',
)
);
$id = $this->factory->entry->create( array( 'form_id' => $form ) );
FrmEntryMeta::add_entry_meta(
$id,
$field->id,
'',
array(
'line1' => '123 Main St',
'city' => 'Baltimore',
'state' => 'MD',
'zip' => '12345',
'country' => 'United States',
)
);
$normal = FrmEntriesController::show_entry_shortcode( array( 'id' => $id ) );
$this->assertTrue( FrmSpamEntriesHelper::mark_as_spam( $id ), 'The entry should be marked as spam.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmSpamOutput::assertTrue()


The method you are trying to call is not defined, which can result in a fatal error.

$spam = FrmEntriesController::show_entry_shortcode( array( 'id' => $id ) );

if ( $this->is_pro_active ) {
$this->assertSame( $spam, do_shortcode( '[frm-show-entry id="' . $id . '"]' ), 'The Pro shortcode should render the same spam entry table.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmSpamOutput::assertSame()


The method you are trying to call is not defined, which can result in a fatal error.

}

foreach ( array( $normal, $spam ) as $html ) {
$this->assertMatchesRegularExpression(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmSpamOutput::assertMatchesRegularExpression()


The method you are trying to call is not defined, which can result in a fatal error.

'/123 Main St\s*<br\s*\/?>\s*Baltimore, MD 12345\s*<br\s*\/?>United States/',
$html,
'Both normal and spam entries should display the address on separate lines.'
);
$this->assertStringNotContainsString( '&lt;br', $html, 'Formatting breaks should not appear as literal tags.' );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call to an undefined method test_FrmSpamOutput::assertStringNotContainsString()


The method you are trying to call is not defined, which can result in a fatal error.

}
}

/**
* Referrers keep line breaks without rendering submitted markup for normal or spam entries.
*
Expand Down
Loading