Empty description field adds empty line on save #5368

Open
opened 2026-02-05 10:00:36 +03:00 by OVERLORD · 0 comments
Owner

Originally created by @kugarocks on GitHub (Jul 21, 2025).

Describe the Bug

For example, when a book's description is empty, editing and saving it will result in HTML tags being appended to the empty field. As a result, an empty <p> tag is rendered in the description.

Image

Quick Fix

app/Entities/Models/HasHtmlDescription.php

/**
 * Check if the entity has a meaningful description (not just empty HTML tags).
 */
public function hasDescription(): bool
{
    $cleanedHtml = str_replace(['<p>', '</p>', '<br>', '<br/>', "\xC2", "\xA0", " "], '', $this->descriptionHtml());
    return !empty(trim($cleanedHtml));
}
  • resources/views/books/show.blade.php
  • resources/views/chapters/show.blade.php
  • resources/views/shelves/show.blade.php
@if($book->hasDescription())
    <div class="text-muted break-text">{!! $book->descriptionHtml() !!}</div>
@endif

Steps to Reproduce

  1. Go to https://demo.bookstackapp.com/books/bookstack-demo-site
  2. Click Edit on the right side.
  3. Remove description content and save.
  4. Click Edit again and save, it will add an empty line(<p>).

Expected Behaviour

  • No empty line.
  • Trim empty description.

Screenshots or Additional Context

No response

Browser Details

No response

Exact BookStack Version

v25.05.2

Originally created by @kugarocks on GitHub (Jul 21, 2025). ## Describe the Bug For example, when a book's description is empty, editing and saving it will result in HTML tags being appended to the empty field. As a result, an empty `<p>` tag is rendered in the description. <img width="961" height="253" alt="Image" src="https://github.com/user-attachments/assets/1d820702-4ade-41a9-b53b-63b57051c24a" /> ## Quick Fix `app/Entities/Models/HasHtmlDescription.php` ```php /** * Check if the entity has a meaningful description (not just empty HTML tags). */ public function hasDescription(): bool { $cleanedHtml = str_replace(['<p>', '</p>', '<br>', '<br/>', "\xC2", "\xA0", " "], '', $this->descriptionHtml()); return !empty(trim($cleanedHtml)); } ``` - `resources/views/books/show.blade.php` - `resources/views/chapters/show.blade.php` - `resources/views/shelves/show.blade.php` ```php @if($book->hasDescription()) <div class="text-muted break-text">{!! $book->descriptionHtml() !!}</div> @endif ``` ### Steps to Reproduce 1. Go to [https://demo.bookstackapp.com/books/bookstack-demo-site](https://demo.bookstackapp.com/books/bookstack-demo-site) 2. Click `Edit` on the right side. 3. Remove description content and save. 4. Click `Edit` again and save, it will add an empty line(`<p>`). ### Expected Behaviour - No empty line. - Trim empty description. ### Screenshots or Additional Context _No response_ ### Browser Details _No response_ ### Exact BookStack Version v25.05.2
OVERLORD added the 🐛 Bug label 2026-02-05 10:00:36 +03:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#5368