Skip to content

Commit

Permalink
Correctly match newlines whitin htmltags. (#122)
Browse files Browse the repository at this point in the history
* Correctly match newlines in tags.

* Revert regex to current implementation while adding the PCRE_DOTALL modifier.

---------

Co-authored-by: Anne Zijlstra <[email protected]>
  • Loading branch information
pharixces and Anne Zijlstra authored Jan 22, 2025
1 parent 88f817a commit acd361c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Caxy/HtmlDiff/AbstractDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ protected function convertHtmlToListOfWords(string $text) : array
// Normalize no-break-spaces to regular spaces
$text = str_replace("\xc2\xa0", ' ', $text);

preg_match_all('/<.+?>|[^<]+/mu', $text, $sentencesAndTags, PREG_SPLIT_NO_EMPTY);
preg_match_all('/<.+?>|[^<]+/mus', $text, $sentencesAndTags, PREG_SPLIT_NO_EMPTY);

foreach ($sentencesAndTags[0] as $sentenceOrHtmlTag) {
if ($sentenceOrHtmlTag === '') {
Expand Down
25 changes: 25 additions & 0 deletions tests/fixtures/HtmlDiff/multiline-tag.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<options>
<option type="boolean" name="setKeepNewLines" value="true" />
<option type="boolean" name="setPurifierEnabled" value="false" />
</options>

<oldText>
<li
attribute="value">
value
</li>
</oldText>

<newText>
<li
attribute="value">
newvalue
</li>
</newText>

<expected>
<li
attribute="value">
<del class="diffmod">value</del><ins class="diffmod">newvalue</ins>
</li>
</expected>

0 comments on commit acd361c

Please sign in to comment.