Closed (duplicate)
Project:
Drupal core
Version:
8.0.x-dev
Component:
mail system
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
28 May 2011 at 21:03 UTC
Updated:
29 Jul 2014 at 19:35 UTC
Paste this
$html = "<p>line 1<br />\nline 2<br />line 3</p><p>paragraph</p>";
dpm($html);
dpm(drupal_html_to_text($html));
into Devel's Execute PHP textarea (devel/php) and you'll get
<p>line 1<br />
line 2<br />line 3</p><p>paragraph</p>line 1line 2line 3paragraph
What you should get is
<p>line 1<br />
line 2<br />line 3</p><p>paragraph</p>line 1
line 2
line 3
paragraph
The culprit is the last change in this commit.
The commit points to #356074: Provide a sequences API, but this is completely unrelated. Apparently, the committer had applied at least one additional patch when he committed 356074, but I haven't been able to find the other issue.
Here's a patch that adds the newline back.
| Comment | File | Size | Author |
|---|---|---|---|
| drupal_html_to_text-linebreaks.patch | 580 bytes | salvis |
Comments
Comment #1
salvisComment #2
droplet commentedRTBC. but leave it for one more to review it
Comment #3
marcingy commentedDoes this need to be applied to d8 first?
Comment #4
salvisYes, D8 first, thanks!
D6 is fine, the
"\n"is still there in D6 (line 406 of 6.x), only D7 was borked.Comment #5
droplet commented@salvis,
thanks. the API site is wrong. :(
Comment #6
damien tournoud commentedThis is just completely by design. This was a bug in the function now fixed. Fixing the remaining bugs is handled by #299138: Improve \Drupal\Core\Utility\Mail::htmlToText().
Comment #7
salvisWell, no, it's not working as designed (or at least not as it's supposed to work). It's a regression that was introduced in D7 with the commit that I linked to. I don't remember having any problems with the D6 version of drupal_html_to_text().
Thank you for the link. I'm fine with having this (and any other newly introduced bugs) fixed elsewhere, which makes this issue a duplicate.
It would be nice if you could use a kinder, less condescending tone (see http://drupal.org/dcoc).
Comment #8
damien tournoud commentedThis is *by design*. In HTML line breaks are *not* significant.
drupal_html_to_text()takes HTML as the input and returns an acceptable plain-text representation. It should (and does in Drupal 7, since fixed) collapse whitespace.Comment #9
damien tournoud commentedOk, I misread.
Comment #10
salvisThank you for your graceful apology, Damien.
Just for the sake of completeness here's what I found out about this issue: #407452-64: Remove use of drupal_html_to_text() from system mails is what was committed inadvertently, which was apparently an unfinished attempt to enable drupal_mail() to send HTML emails.
The error was noticed a year ago in #299138-48: Improve \Drupal\Core\Utility\Mail::htmlToText(), but instead of rolling back the inadvertent commit or raising priority to critical (after all, D7 is unable to send emails with any reasonable formatting such as line breaks), this has been dragging on ever since.
In #57 sun, the author of the premature patch, concluded that Test results are clear, the current function is horribly broken, and in #69 pillarsdotnet posted essentially the same patch as mine above. That was 10 weeks ago.
Seeing that that thread might take a while to come to a conclusion, pillarsdotnet tried to get this fixed quickly with #1130198: Regression: line-breaks are mangled by \Drupal\Core\Utility\Mail::htmlToText(), but apparently we wanted to release 7.1 with broken mail functionality. Sorry about the sarcasm here...
#128 and #129 provide essential information, which I had been missing before.
My conclusion is that drupal_mail() is and for the foreseeable future remains unusable, but the D6 mail.inc should work just fine. I'll add that to my project for now, renaming the functions to avoid conflicts, of course.