Skip to content

fix(opac): stop injecting <br> between HTML paragraphs in descriptions (#313) - #314

Open
fabiodalez-dev wants to merge 1 commit into
mainfrom
fix/opac-description-br-313
Open

fix(opac): stop injecting <br> between HTML paragraphs in descriptions (#313)#314
fabiodalez-dev wants to merge 1 commit into
mainfrom
fix/opac-description-br-313

Conversation

@fabiodalez-dev

Copy link
Copy Markdown
Owner

Fixes #313.

The bug

On the OPAC, a book description whose source is clean <p>…</p> paragraphs rendered with visible extra spacing — a stray <br> between every paragraph.

Cause

The description (and custom rich-text fields) were rendered with sanitizeHtml(nl2br($value, false)). TinyMCE separates its <p> blocks with a literal \n, so nl2br turned every inter-block newline into a <br>:

<p>Para uno.</p><br>
<p>Para due.</p><br>
<p>Para tre.</p>

nl2br is only right for the other kind of description — legacy plain text imported with bare newlines.

Fix

HtmlHelper::richText() applies nl2br only when the value is plain text (no block/line HTML) and leaves already-structured HTML untouched, then sanitises. Plain-text descriptions keep their line breaks; editor HTML renders as authored. All five call sites (book description + custom fields, on the OPAC book-detail and the admin scheda) use it.

Test

tests/richtext-nl2br-313.unit.php (12 checks): HTML paragraphs render without an injected <br>, plain text keeps its breaks, block markers (br/div/ul/heading) suppress nl2br, sanitisation still strips scripts, and the reporter's Cyrillic data renders clean. PHPStan level 5 clean.

#313)

The book description and custom rich-text fields were rendered with
sanitizeHtml(nl2br($value, false)). Editor (TinyMCE) HTML separates its <p>
blocks with a literal "\n", so nl2br turned every inter-block newline into a
stray <br> and double-spaced the output — reported on the OPAC with clean
<p>…</p> source producing visible gaps between paragraphs.

Add HtmlHelper::richText(): it applies nl2br only when the value is plain text
(no block/line HTML), and leaves already-structured HTML untouched, so legacy
imported descriptions still keep their newlines while editor HTML renders as
authored. All five call sites (book description + custom fields on the OPAC
book-detail and the admin scheda) now use it.

Test: tests/richtext-nl2br-313.unit.php — HTML paragraphs render without an
injected <br>, plain text keeps its breaks, block markers (br/div/ul/heading)
suppress nl2br, sanitisation still strips scripts, and the reporter's Cyrillic
data renders clean.
@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@fabiodalez-dev, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cbcd6108-c043-4d90-bb5c-139db36fb9e3

📥 Commits

Reviewing files that changed from the base of the PR and between 14e4281 and 80000ef.

📒 Files selected for processing (4)
  • app/Support/HtmlHelper.php
  • app/Views/frontend/book-detail.php
  • app/Views/libri/scheda_libro.php
  • tests/richtext-nl2br-313.unit.php

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OPAC: In book description <br> tags are added between paragraphs

1 participant