Skip to content

Commit

Permalink
Merge pull request #5 from worksome/JIRA-8030_resolve-plaintext-issue
Browse files Browse the repository at this point in the history
fix: JIRA-8030 Resolve plain-text encoding
  • Loading branch information
owenvoke authored Nov 15, 2022
2 parents b4dea21 + a1b23ea commit 1d464f3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Html2Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public static function getDocument(string $html): DOMDocument
$html = '<body>' . $html . '</body>';
}

$html = (string) preg_replace('/&(?![a-z]+?;)/mi', '&amp;', $html);

$load_result = $doc->loadHTML($html);

if (! $load_result) {
Expand Down
3 changes: 2 additions & 1 deletion tests/Html2TextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

$output = Html2Text::convert($input, $config);

expect($output)->toBe($expected);
expect(trim($output))->toBe(trim($expected));
})->with([
'Basic' => 'basic',
'Anchor tags' => 'anchors',
'More anchor tags' => 'more-anchors',
'Break tag' => 'br',
'Ampersand (&)' => 'ampersand',
'Break tags' => 'brs',
'Tables' => 'table',
'Non-breaking spaces (NBSP tag)' => 'nbsp',
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/ampersand.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
& &amp;
1 change: 1 addition & 0 deletions tests/fixtures/ampersand.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
& &

0 comments on commit 1d464f3

Please sign in to comment.