Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The drupal_html_to_text()
function was broken by collateral damage from #356074: Provide a sequences API
This is a regression in d7 versus d6 that affects other projects such as Simplenews.
A comprehensive patch/fix is being discussed, but may never get resolved to everyone's satisfaction. As a stopgap, therefore, I suggest that we merely reverse the damage so that the d7 function performs at least as well as the d6 version.
Comments
Comment #1
pillarsdotnet CreditAttribution: pillarsdotnet commentedPatches for d7 and d8:
Comment #2
Simon Georges CreditAttribution: Simon Georges commentedSubscribe, in case this one goes faster than the original one (#299138: Improve \Drupal\Core\Utility\Mail::htmlToText()).
Comment #3
pillarsdotnet CreditAttribution: pillarsdotnet commentedYou can help by posting a review of the patch in #1. An acceptable review would:
Confirm that the patch actually solves the problem. Describe a reproducible test where the current code fails and the patched code succeeds.
Change the issue status from "Needs Review" to "Reviewed and Tested By the Community".
If, after thorough testing, you cannot in good conscience affirm the above, please explain what is lacking in the current patch and I will do my best to address your concerns.
Comment #4
drupjab CreditAttribution: drupjab commentedIs this the same patch as http://drupal.org/node/299138#comment-4193400 (which is for D7)? It looks like it from the text in the actual patch code, but just want to confirm.
Comment #5
pillarsdotnet CreditAttribution: pillarsdotnet commented@rrcjab -- Yes, it's the same patch; just re-rolled against a fresh 8.x checkout.
Comment #6
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #7
drupjab CreditAttribution: drupjab commented@pillarsdotnet Both of them (D7 & D8) have worked from my functional tests. Plain text, full and filtered HTML. Your test suite looks good to me too. I read the discussion, so what's the next step to actually get them in the next official release(s)?
Comment #8
pillarsdotnet CreditAttribution: pillarsdotnet commented@rrcjab -- The next step is someone other than the patch-writer having sufficient confidence and fortitude to mark the issue RTBC. After that, well... (looking) The oldest patch in a similar status has been waiting for less than a month.
Comment #9
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is an obvious duplicate of #299138: Improve \Drupal\Core\Utility\Mail::htmlToText().
Comment #10
drupjab CreditAttribution: drupjab commented@pillarsdotnet - Well, it was a good effort, :/
I'll start catching up on the other thread now.
Comment #11
pillarsdotnet CreditAttribution: pillarsdotnet commentedPatch in #1 still applies, and the the other issue may still be in debate when D9 ships. Let's fix what we broke in D7 first.
Comment #12
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #13
Damien Tournoud CreditAttribution: Damien Tournoud commentedIt is still a duplicate of #299138: Improve \Drupal\Core\Utility\Mail::htmlToText().
Comment #14
pillarsdotnet CreditAttribution: pillarsdotnet commentedNo, it's not. This is a only a single-line quick-fix reversal of a known regression introduced in D7. #299138 is a much larger issue, which no one is willing to commit until it reaches a level of perfection that may not happen in my lifetime.
Comment #15
Damien Tournoud CreditAttribution: Damien Tournoud commentedWell. The other issue transformed into a massive feature request (partly on your own impulse... support for tables... really?), so let's keep this one for the bug fix.
Can we incorporate some of the tests from the other issue?
Comment #16
Damien Tournoud CreditAttribution: Damien Tournoud commentedComment #17
pillarsdotnet CreditAttribution: pillarsdotnet commented@#15 -- Added tests, made them pass, (by "expecting" whatever results were generated), then removed the ones which are totally n/a.
Wasn't that hard, actually, since I already had a fully-parsed DOM tree.
Comment #18
pillarsdotnet CreditAttribution: pillarsdotnet commentedLooks like testbots are fixed.
Comment #20
pillarsdotnet CreditAttribution: pillarsdotnet commentedDunno; tests pass locally and the testbot is not displaying any of the
$this->verbose()
output. Trying again...Comment #22
pillarsdotnet CreditAttribution: pillarsdotnet commentedMoved the
verbose()
text back into the assertion message so I can figure out why the tests are failing.Comment #23
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #25
pillarsdotnet CreditAttribution: pillarsdotnet commentedGrrr....
Comment #27
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #29
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #31
pillarsdotnet CreditAttribution: pillarsdotnet commentedComment #33
pillarsdotnet CreditAttribution: pillarsdotnet commented#31: drupal_html_to_text-fix_regression-1130198-31.patch queued for re-testing.
Comment #34
Damien Tournoud CreditAttribution: Damien Tournoud commentedThere is no way, ever, to use
url()
in aDrupalUnitTestCase
, as this function needs to access the database to resolve URL aliases. I'm not sure how the tests can pass for your locally :)Comment #35
pillarsdotnet CreditAttribution: pillarsdotnet commented@#34 -- I dunno either, but they did. The tests in #299138-134 have url() calls, and they passed, too. Other core tests also contain url() calls:
There are more in
openid.test
,book.test
,profile.test
,update.test
,user.test
,path.test
,image.test
,comment.test
,color.test
,rdf.test
,file.test
,locale.test
,aggregator.test
,translation.test
,filter.test
,trigger.test
,search.test
,simpletest.test
,xmlrpc.test
,bootstrap.test
,common.test
,file.test
,path.test
,ajax.test
,form.test
,menu.test
, andtaxonomy.test
.Comment #36
Damien Tournoud CreditAttribution: Damien Tournoud commentedPlease switch to DrupalWebTestCase. It is simply not valid to use url() inside a DrupalUnitTestCase. I'm not completely sure why it still somehow work here, running this through the UI rightly gives me a PDO error.
Also, could you please add
@todo
everywhere in the test where you think the current behavior is not the intended one? Specifically,testDrupalHtmltoTextCollapsesWhitespace
should say that the current behavior is in no way correct.Comment #37
Damien Tournoud CreditAttribution: Damien Tournoud commentedComment #38
pillarsdotnet CreditAttribution: pillarsdotnet commentedThat would be just about everywhere, all right. Working on it...
Comment #39
pillarsdotnet CreditAttribution: pillarsdotnet commentedSwitched to
DrupalWebTestCase
and added@todo
lines. Removing the "Quick fix" tag, as it no longer applies.Comment #41
pillarsdotnet CreditAttribution: pillarsdotnet commented#39: drupal_html_to_text-fix_regression-1130198-39.patch queued for re-testing.
Comment #42
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis is likely to fail, and likely to be due to the use of DrupalUnitTestCase before.
The rest looks super nice. Waiting for the test bot verdict.
Comment #43
pillarsdotnet CreditAttribution: pillarsdotnet commentedBot is green.
Comment #44
Damien Tournoud CreditAttribution: Damien Tournoud commentedWeirdest thing. The tests are failing here locally, both on 8.x and 7.x. It see the proper behavior around absolute URLs:
It seems that the test bots are running with a broken base URL.
Anyway, you should restore those calls to
url()
in there, they seem valid.Comment #45
pillarsdotnet CreditAttribution: pillarsdotnet commentedWill do, after I re-test locally. @sun gave me some pointers on IRC. My local test must run with clean urls turned off, and with Drupal installed in a subdirectory, else the results aren't valid.
Comment #46
pillarsdotnet CreditAttribution: pillarsdotnet commentedFixed.
Comment #47
sunsubscribing
Comment #48
pillarsdotnet CreditAttribution: pillarsdotnet commented#46: drupal_html_to_text-fix_regression-1130198-46.patch queued for re-testing.
Comment #49
pillarsdotnet CreditAttribution: pillarsdotnet commentedIssue and patch summary
drupal_html_to_text()
functionality:Comment #50
pillarsdotnet CreditAttribution: pillarsdotnet commentedAdding tests-only and tests+fix patch to highlight exactly what this patch changes.
Comment #51
clayball CreditAttribution: clayball commentedThe patch applied cleanly to 8.x and 7.x.
Email from my 7.x install looks MUCH better now.
Thank you for doing this.
Status has been updated.
However, maybe someone else would like to/should confirm?
Comment #52
webchickYeeaahhh...
pillarsdotnet, please don't shoot me, but I would feel better about sign-off on this from Damien, since he seems to be one of few people who understands the intricacies here tech-wise and could give a final sign-off review.
I would really like to get this into 7.3, though. Thanks so much for your work on this!!
Comment #53
pillarsdotnet CreditAttribution: pillarsdotnet commented(sigh)
Comment #54
pillarsdotnet CreditAttribution: pillarsdotnet commented#50: drupal_html_to_text-fix_regression-1130198-tests+fix.patch queued for re-testing.
Comment #55
attiks CreditAttribution: attiks commentedsubscribing
Comment #56
Damien Tournoud CreditAttribution: Damien Tournoud commentedThis patch is perfect. Thanks @pillarsdotnet for your hard work on this.
*Please*, let's get this in 7.3. It's part of the things in Drupal 7 that are *so broken* it's not even funny.
Comment #57
Damien Tournoud CreditAttribution: Damien Tournoud commentedIn addition, the fix of this patch is so tiny and it adds so many tests that it cannot possibly break anything.
Comment #58
webchickSorry. This was marked RTBC too late for 7.3/7.4. But 7.5, that sure sounds nice! :)
Great work on this patch, and all of the extensive tests. Really happy to see this fixed, and I know all mail-using Drupal folks will be, too!
Committed to 8.x and 7.x.
Comment #60
coredumperror CreditAttribution: coredumperror commentedI'm sorry to bring this up in such an old, closed issue, but there's a slight problem with this patch: it doesn't support the
$conf['mail_line_endings']
override thatMAIL_LINE_ENDINGS
's documentation refers to, on line 11 ofincludes/mail.inc
. The only other place in core that refers toMAIL_LINE_ENDINGS
(modules/system/system.mail.inc
) uses it like this:While this patch uses it without the possibility of override:
I'm bumping this down to normal, since it only affects people who use the override.
I've attached a patch that remedies this problem. However, I have Drupal 7.16, so my patch may not have the right line numbers for Drupal 8's version of
includes/mail.inc
. It's just a one-liner, though, so it's easy enough to apply manually.Comment #62
sunI also noticed that over in #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5 — we should additionally adjust some tests (as in the patch over there) to force MAIL_LINE_ENDINGS to be \n and make mail formatting tests pass on Windows (which are failing currently, since the actual formatted output uses \r\n).
I asked myself why @coredumperror re-opened this issue instead of creating a separate follow-up, but yeah, #58 states this was committed to both D8 and D7, so it's indeed a regression.
Comment #63
ianthomas_ukComment #64
BerdirLooks like that follow-up has been addressed somewhere else in Drupal 8, please open a new issue if it's still an issue for D7.