Skip to content

Conversation

Copy link

Copilot AI commented Dec 27, 2025

The library was normalizing all whitespace (including   entities), making it impossible to detect when spaces were added or removed from HTML text.

Changes

  • Modified AbstractDiff::convertHtmlToListOfWords(): Conditionally preserve non-breaking spaces (\xc2\xa0) when spaceMatching is enabled
  • Modified AbstractDiff::normalizeWhitespaceInHtmlSentence(): Skip collapsing multiple consecutive spaces when spaceMatching is enabled (still normalizes newlines)
  • Added test fixtures: nbsp-spaces-added.html validates space detection, nbsp-spaces-default-behavior.html validates backward compatibility

Usage

$config = HtmlDiffConfig::create();
$config->setSpaceMatching(true);

$old = '<p>Text&nbsp; &nbsp;</p>';
$new = '<p>Text&nbsp; &nbsp; &nbsp; &nbsp;</p>';

$diff = HtmlDiff::create($old, $new, $config);
// Now detects and highlights the additional spaces

The spaceMatching option defaults to false, preserving existing behavior.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/doctrine/cache/zipball/56cd022adb5514472cb144c087393c1821911d09
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/o8M0vS /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/ezyang/htmlpurifier/zipball/b287d2a16aceffbf6e0295559b39662612b77fcf
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/o8M0vS /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/o8M0vS /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/o8M0vS /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/phpunit/zipball/945d0b7f346a084ce5549e95289962972c4272e5
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/539c6691e0623af6dc6f9c20384c120f963465a0
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/o8M0vS /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/o8M0vS /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/o8M0vS /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/o8M0vS /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/wh8Yuv /usr/bin/composer install --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Issue with detecting additional/removed spaces in html text</issue_title>
<issue_description>Hello. I noticed that if some additional spaces were added into a text or removed from a text then there is no difference detected. Is it possible to configure HtmlDiff to handle this case? If it's not then maybe it's worth to implement/fix?

Example:

  • Old content:
<p>Just a simple text&nbsp; &nbsp;</p>
  • New cotent:
<p>Just a simple text&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</p>

Expected output should show that additional spaces were added.

Thanks for any feedback or tips!</issue_description>

<agent_instructions>New configuration option that doesn't break backwards compatibility</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link

coderabbitai bot commented Dec 27, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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

Copilot AI and others added 2 commits December 27, 2025 19:25
Co-authored-by: jschroed91 <2540804+jschroed91@users.noreply.github.com>
- Modified convertHtmlToListOfWords to respect spaceMatching config
- Modified normalizeWhitespaceInHtmlSentence to preserve multiple spaces when spaceMatching is enabled
- Added test case for nbsp space changes with spaceMatching enabled
- Added test case for backwards compatibility (default behavior)
- All existing tests pass

Co-authored-by: jschroed91 <2540804+jschroed91@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue with detecting additional spaces in HTML text Implement spaceMatching config to detect space changes in HTML diffs Dec 27, 2025
Copilot AI requested a review from jschroed91 December 27, 2025 19:33
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.

Issue with detecting additional/removed spaces in html text

2 participants