Skip to content

Show NL instead of BR when displaying spam entry - #3572

Merged
Crabcyborg merged 1 commit into
masterfrom
show_nl_instead_of_br_when_displaying_spam_entry
Oct 14, 2026
Merged

Crabcyborg merged 1 commit into
masterfrom
show_nl_instead_of_br_when_displaying_spam_entry

Conversation

@Crabcyborg

Copy link
Copy Markdown
Contributor

Fixes https://github.com/Strategy11/formidable-pro/issues/6841

A spam entry is intentionally fully escaped - no HTML should work for a spam entry.

But this update changes the escapes <br> tags to \n so line breaks look better.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: Strategy11/formidable-forms/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 067c59e0-ef37-4040-a5bf-8382a64f3785
📥 Commits

Reviewing files that changed from the base of the PR and between 37b7b7a and 6772e97.

📒 Files selected for processing: 2
  • classes/helpers/FrmSpamEntriesHelper.php
  • tests/phpunit/misc/test_FrmSpamOutput.php
 ______________________________
< Here's looking at you, code. >
 ------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Crabcyborg Crabcyborg added this to the 7.0 milestone Oct 13, 2026
@franky-the-going-merry franky-the-going-merry Bot added the franky-working Franky is actively reviewing this label Oct 13, 2026
@deepsource-io

deepsource-io Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 37b7b7a...6772e97 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Oct 13, 2026 8:37p.m. Review ↗
JavaScript Oct 13, 2026 8:37p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

$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.

)
);
$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.

$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.

@franky-the-going-merry franky-the-going-merry Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approve at 6772e97. No findings.

The fix is correct and does what the issue (formidable-pro#6841) asks for. Spam values are escaped in FrmSpamEntriesHelper::escape_value(), and FrmFieldValue runs it over the already-built display value, which is where the address field's <br/> separators arrive. They were being escaped into visible &lt;br/&gt;. The change turns <br>, <br/> and <br /> into a newline before esc_html(), so everything else a spammer submits stays escaped.

Live repro (Playground preview env, Lite + Pro; address field and a textarea, entry marked as spam, rendered through FrmEntriesController::show_entry_shortcode() and [frm-show-entry]):

  • On master: the Address cell is 123 Main St &lt;br/&gt;Baltimore, MD 12345 &lt;br/&gt;United States, which is the bug from the issue.
  • On this PR: the same cell is 123 Main St <br />Baltimore, MD 12345 <br />United States, real line breaks. A textarea value with <b>bold</b> <img src=x onerror=alert(1)> still renders as &lt;b&gt;bold&lt;/b&gt; &lt;img src=x onerror=alert(1)&gt; on both, so no markup gets through. The entries list cell for the address reads 123 Main St Baltimore, MD 12345 United States.

Tests: both new tests in test_FrmSpamOutput pass on the PR (5/5, 39 assertions, run in a wordpress-develop checkout with Lite's phpunit.xml and Pro present). With only the one-line change reverted, the two new tests fail. The wider Spam/FrmFieldValue/entries filter shows the same 4 errors with and without the change (the first is test_FrmSpamCompatibility::test_old_addon_blocks_spam_storage), so they come from this local setup, not the PR. I could not read their messages: PHPUnit crashes while printing them.

Not exercised: the admin spam tab in a browser (I rendered the same code paths over HTTP instead), Views and email placeholders that call escape_value() through FrmProContent, where a bare newline will not show as a break unless the output is run through nl2br, and the review skills (a one-line change plus tests, read in full instead). CI is skipping every job except typos, and Psalm and the DeepSource and Scrutinizer checks were still pending when I started.

@franky-the-going-merry franky-the-going-merry Bot removed franky-review franky-working Franky is actively reviewing this labels Oct 13, 2026

@garretlaxton garretlaxton left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This fix works good!

@Crabcyborg
Crabcyborg marked this pull request as ready for review October 14, 2026 12:09
@Crabcyborg

Copy link
Copy Markdown
Contributor Author

Thank you Garret!

🚀

@Crabcyborg
Crabcyborg merged commit 20f0d29 into master Oct 14, 2026
57 of 59 checks passed
@Crabcyborg
Crabcyborg deleted the show_nl_instead_of_br_when_displaying_spam_entry branch October 14, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants