MailFormatHelper::htmlToText() incorrect handling of newlines in anchor links

Created on 16 September 2008, about 16 years ago
Updated 7 May 2024, 6 months ago

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. Review
  3. Commit
πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
BaseΒ  β†’

Last updated about 2 hours ago

Created by

πŸ‡¬πŸ‡§United Kingdom Liberation

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡ΏNew Zealand quietone

    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.

  • First commit to issue fork.
  • Pipeline finished with Failed
    7 months ago
    Total: 638s
    #162022
  • πŸ‡¦πŸ‡ΊAustralia pameeela

    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!

  • πŸ‡¦πŸ‡ΊAustralia pameeela

    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.

  • Pipeline finished with Failed
    7 months ago
    Total: 520s
    #162062
  • πŸ‡¦πŸ‡ΊAustralia pameeela
  • First commit to issue fork.
  • Pipeline finished with Failed
    7 months ago
    Total: 193s
    #162135
  • Pipeline finished with Failed
    7 months ago
    Total: 487s
    #162138
  • Pipeline finished with Failed
    7 months ago
    Total: 561s
    #162397
  • πŸ‡¦πŸ‡ΊAustralia skipper-vp

    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".
  • Pipeline finished with Success
    7 months ago
    Total: 658s
    #162958
  • Status changed to Needs review 7 months ago
  • πŸ‡¦πŸ‡ΊAustralia pameeela
  • πŸ‡³πŸ‡ΏNew Zealand quietone

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

  • πŸ‡¦πŸ‡ΊAustralia pameeela

    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?

  • πŸ‡¦πŸ‡ΊAustralia pameeela
  • Pipeline finished with Success
    7 months ago
    Total: 505s
    #163054
  • Pipeline finished with Success
    7 months ago
    Total: 595s
    #163070
  • πŸ‡¦πŸ‡ΊAustralia pameeela

    @quietone confirmed to add comments to new tests.

  • Status changed to RTBC 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    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.

  • Status changed to Needs work 6 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

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

Production build 0.71.5 2024