Problem/Motivation

MailFormatHelper::htmlToText() does not handle the situation where there are newlines in the link text. For example, given the test sequence:

$html_text = "<a href=\"http://some.url\">Link \ntext</a>";
$plain_text = drupal_html_to_text($html_text);

We get:

Link text

when we should get:

Link text [1]

[1] http://some.url

Steps to reproduce

Proposed resolution

Fix the regex to strip \n from anchor text.

Remaining tasks

  1. Patch
  2. Test
  3. Review
  4. Commit

Issue fork drupal-309343

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

cspitzlay’s picture

This problem is still around in Drupal 6.15.
I encountered it trying to send multipart/alternative emails using the mimemail module
which uses the function drupal_html_to_text from core internally.

I feel that making that change in core is to be preferred to patching mimemail
which would mean mostly duplicating the functionality of drupal_html_to_text.

lyricnz’s picture

Version: 6.4 » 8.x-dev

Still in D8.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

mile23’s picture

Title: drupal_html_to_text handling of newlines in anchor links » MailFormatHelper::htmlToText() incorrect handling of newlines in anchor links
Component: system.module » base system
Issue summary: View changes
Status: Active » Needs review
StatusFileSize
new4.75 KB

drupal_html_to_text() got moved: https://www.drupal.org/node/2309379

Here's a test-only patch which proves that the parser still misinterprets newlines.

The test is moved and renamed from the system module. It was a functional test, now it's a kernel test.

Status: Needs review » Needs work

The last submitted patch, 6: 309343_6.patch, failed testing. View results

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Version: 9.5.x-dev » 10.1.x-dev
Issue summary: View changes
Issue tags: +Bug Smash Initiative, +Needs issue summary update
StatusFileSize
new855 bytes

I tested this on Drupal 10.1.x. I added the one new test string to \Drupal\Tests\system\Functional\Mail\HtmlToTextTest::testTags and ran the test. The test did fail. So, base on that this is still valid. I also tried the proposed fix in the original patch and the test still failed.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

pameeela made their first commit to this issue’s fork.

pameeela’s picture

Made a MR with the updated test and initial fix just to confirm what @quietone said. So this still needs work, but it feels fixable by someone better at regex than me!

pameeela’s picture

Added this as a new test rather than modifying the existing test, and reverted the initial fix. So this is currently a test-only change.

pameeela’s picture

Issue summary: View changes

skipper-vp made their first commit to this issue’s fork.

skipper-vp’s picture

Edited pattern and added replacing of the new lines.
\Drupal\Tests\system\Functional\Mail\HtmlToTextTest passes for me locally.
But on the build this one fails:

 1) Drupal\Tests\comment\Functional\CommentPreviewTest::testCommentPreview
    Failed asserting that '3' is an instance of interface
    "Drupal\Component\Render\MarkupInterface".
pameeela’s picture

Status: Needs work » Needs review
quietone’s picture

Only took a brief look and think that some comments should be added.

pameeela’s picture

I have added a comment explaining the regex. Uncertain about adding a comment for the test as it's one among many and none of the others have comments (other than @todos that are.... a bit confusing anyway). Should we be adding a comment to new tests as a rule?

pameeela’s picture

pameeela’s picture

@quietone confirmed to add comments to new tests.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update +Needs Review Queue Initiative

Started taking a look at this several hours ago and got distracted

But issue summary appears fine to me so removing that tag

Ran the test-only feature https://git.drupalcode.org/issue/drupal-309343/-/jobs/1501515 to show coverage

Appears feedback has been addressed and changes look fine to me.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I left a couple of comments on the MR that need addressing.

mdranove made their first commit to this issue’s fork.

mdranove’s picture

Status: Needs work » Needs review

Updated pattern, added test based on feedback. Seeing expected result when tags are placed inside of <a>. Moving to NR.

acbramley’s picture

Status: Needs review » Reviewed & tested by the community

Changes look good and comments have been addressed.

  • catch committed a24f3ca3 on 11.x
    Issue #309343 by pameeela, skipper-vp, mdranove, quietone, Liberation,...

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.