Skip to content

Preserve non-breaking spaces during whitespace collapsing#139

Merged
voku merged 1 commit into
masterfrom
copilot/fix-preserve-nbsp-character
May 18, 2026
Merged

Preserve non-breaking spaces during whitespace collapsing#139
voku merged 1 commit into
masterfrom
copilot/fix-preserve-nbsp-character

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 18, 2026

Default minification was collapsing literal non-breaking spaces as if they were ordinary whitespace, which could erase meaningful content such as  -backed spacing. This change keeps non-breaking spaces intact while still compacting regular collapsible whitespace.

  • Regression coverage

    • Add a focused PHPUnit case for the default new HtmlMin()->minify($html) path where a literal NBSP-separated text node must survive minification unchanged.
  • Whitespace collapsing

    • Narrow the whitespace-compaction regex to HTML ASCII whitespace (space, tab, form feed, CR, LF) instead of Unicode [:space:].
    • Preserve U+00A0 /   in text nodes while retaining existing whitespace normalization behavior for normal collapsible whitespace.
  • Behavioral example

    $htmlMin = new HtmlMin();
    $nbsp = html_entity_decode(' ', ENT_QUOTES | ENT_HTML5, 'UTF-8');
    
    $html = '<span>' . $nbsp . ' ' . $nbsp . '</span>';
    
    echo $htmlMin->minify($html);
    // Before: <span></span>
    // After:  <span>   </span>

This change is Reviewable

@voku voku marked this pull request as ready for review May 18, 2026 16:26
@sonarqubecloud
Copy link
Copy Markdown

@voku
Copy link
Copy Markdown
Owner

voku commented May 18, 2026

Fix #136

@voku voku merged commit b34368c into master May 18, 2026
18 of 19 checks passed
@coveralls
Copy link
Copy Markdown

coveralls commented May 18, 2026

Coverage Status

coverage: 95.727%. remained the same — copilot/fix-preserve-nbsp-character into master

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.

3 participants