Skip to content

Empty description field adds empty line on save #5724

@kugarocks

Description

@kugarocks

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions