Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

erusev/parsedown-extra doesn't work with newer libxml versions #3480

Closed
amorphine opened this issue Apr 2, 2018 · 8 comments
Closed

erusev/parsedown-extra doesn't work with newer libxml versions #3480

amorphine opened this issue Apr 2, 2018 · 8 comments

Comments

@amorphine
Copy link

amorphine commented Apr 2, 2018

Intro

erusev/parsedown-extra is a dependency of october/rain

Expected behavior

Emails should be parsed and sent.

Actual behavior

October CMS does not send HTML-emails due to incompatibility of erusev/parsedown-extra with newer versions of libxml throwing an error

Type error: Argument 1 passed to DOMNode::replaceChild() must be an instance of DOMNode, null given" on line 473 of /usr/share/nginx/html/predelanet/vendor/erusev/parsedown-extra/ParsedownExtra.php

Reproduce steps
  1. Get a newer environment. As of me it happened with the next docker image:
FROM php:7.1-fpm-alpine

RUN apk upgrade --update && apk --no-cache add \
    bash nodejs autoconf file g++ gcc binutils isl libatomic libc-dev musl-dev make re2c libstdc++ libgcc libcurl \
    curl-dev binutils-libs mpc1 mpfr3 gmp libgomp coreutils freetype-dev libjpeg-turbo-dev libltdl libmcrypt-dev \
    libpng-dev openssl-dev libxml2-dev expat-dev icu-dev libxslt libxslt-dev

RUN docker-php-ext-install -j$(nproc) iconv mysqli pdo pdo_mysql curl bcmath mcrypt mbstring json xml zip opcache intl xsl \
	&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
	&& docker-php-ext-install -j$(nproc) gd

RUN apk --no-cache add libintl gettext-dev

RUN docker-php-ext-install -j$(nproc) gettext

RUN apk add --no-cache $PHPIZE_DEPS \
    && echo no | pecl install redis \
    && docker-php-ext-enable redis

RUN apk add --no-cache $PHPIZE_DEPS \
    && pecl install xdebug \
    && docker-php-ext-enable xdebug

CMD ["php-fpm"]

php-version may be set ( tried from php 7.1.6 up to 7.1.15)
libxml version of Alpine Linux here is

bash-4.3# apk info -a libxml2
libxml2-2.9.5-r0 description:
XML parsing library, version 2

Trying to send an email throws an error. Heres a code example taken right from the library and wich behaves differently on my host machine and docker container


$elementMarkup = '
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8"/>
        <title>Title</title>
    </head>
    <body>
    
    </body>
    </html>
';

$DOMDocument = new DOMDocument();

# http://stackoverflow.com/q/11309194/200145
$elementMarkup = mb_convert_encoding($elementMarkup, 'HTML-ENTITIES', 'UTF-8');

# http://stackoverflow.com/q/4879946/200145
$DOMDocument->loadHTML($elementMarkup);
$DOMDocument->removeChild($DOMDocument->doctype);
$DOMDocument->replaceChild($DOMDocument->firstChild->firstChild->firstChild, $DOMDocument->firstChild);
October build

434

Possible solutions

May be you should use your own fork of the library.
Possible solution is shown here. An explanation is given here

The code of the library looks a bit fragile. I'm surprised I worked as it should for so long time.

@LukeTowers
Copy link
Contributor

@amorphine could you post the exact steps to take to reproduce this issue using this library and break down where the faulty dependency code is getting called?

@amorphine
Copy link
Author

@LukeTowers
Hello, Luke. Thanks for reply.
To simplify reproducing let's try to send a test mail from admin panel when editing templates:

image

Excuse Russian, I'm sure it's clear what part of backend the action takes place.
As you can see from the screenshot bug is reproduced even with standard CMS actions (all email sendings from my components are broken too).

I'm not sure what you want me to do to break down where the faulty dependency code is getting called, so I attach a call stack formed by xdebug:

ParsedownExtra.php:473, October\Rain\Parse\Parsedown\Parsedown->processTag()
ParsedownExtra.php:228, October\Rain\Parse\Parsedown\Parsedown->blockMarkupComplete()
Parsedown.php:276, October\Rain\Parse\Parsedown\Parsedown->lines()
Parsedown.php:39, October\Rain\Parse\Parsedown\Parsedown->text()
ParsedownExtra.php:46, October\Rain\Parse\Parsedown\Parsedown->text()

Markdown.php:87, October\Rain\Parse\Markdown->parseInternal()

Markdown.php:46, October\Rain\Parse\Markdown->parse()
Markdown.php:58, October\Rain\Parse\Markdown->parseSafe()
Facade.php:221, Illuminate\Support\Facades\Facade::__callStatic()
MailManager.php:168, Illuminate\Support\Facades\Facade::parseSafe()
MailManager.php:168, System\Classes\MailManager->render()
MailManager.php:177, System\Classes\MailManager->renderTemplate()
MailManager.php:132, System\Classes\MailManager->addContentToMailerInternal()
MailManager.php:92, System\Classes\MailManager->addContentToMailer()
ServiceProvider.php:333, System\ServiceProvider->System\{closure}()
Dispatcher.php:233, call_user_func_array:{/usr/share/nginx/html/predelanet/vendor/october/rain/src/Events/Dispatcher.php:233}()
Dispatcher.php:233, October\Rain\Events\Dispatcher->dispatch()
Dispatcher.php:197, October\Rain\Events\Dispatcher->fire()
Facade.php:221, Illuminate\Support\Facades\Facade::__callStatic()
Mailer.php:335, Illuminate\Support\Facades\Facade::fire()
Mailer.php:335, October\Rain\Mail\Mailer->addContent()
Mailer.php:59, October\Rain\Mail\Mailer->send()
Mailer.php:136, October\Rain\Mail\Mailer->sendTo()
Facade.php:221, Illuminate\Support\Facades\Facade::__callStatic()
MailTemplates.php:83, Illuminate\Support\Facades\Facade::sendTo()
MailTemplates.php:83, System\Controllers\MailTemplates->onTest()
Controller.php:536, call_user_func_array:{/usr/share/nginx/html/predelanet/modules/backend/classes/Controller.php:536}()
Controller.php:536, System\Controllers\MailTemplates->runAjaxHandler()
Controller.php:419, System\Controllers\MailTemplates->execAjaxHandlers()
Controller.php:229, System\Controllers\MailTemplates->run()
BackendController.php:95, Backend\Classes\BackendController->run()
Controller.php:54, call_user_func_array:{/usr/share/nginx/html/predelanet/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54}()
Controller.php:54, Backend\Classes\BackendController->callAction()
ControllerDispatcher.php:45, Illuminate\Routing\ControllerDispatcher->dispatch()
Route.php:212, Illuminate\Routing\Route->runController()
Route.php:169, Illuminate\Routing\Route->run()
Router.php:658, October\Rain\Router\CoreRouter->Illuminate\Routing\{closure}()
Pipeline.php:30, Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}()
SubstituteBindings.php:41, Illuminate\Routing\Middleware\SubstituteBindings->handle()
Pipeline.php:149, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure}()
Pipeline.php:53, Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}()
ShareErrorsFromSession.php:49, Illuminate\View\Middleware\ShareErrorsFromSession->handle()
Pipeline.php:149, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure}()
Pipeline.php:53, Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}()
StartSession.php:63, Illuminate\Session\Middleware\StartSession->handle()
Pipeline.php:149, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure}()
Pipeline.php:53, Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}()
AddQueuedCookiesToResponse.php:37, Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
Pipeline.php:149, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure}()
Pipeline.php:53, Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}()
EncryptCookies.php:59, Illuminate\Cookie\Middleware\EncryptCookies->handle()
Pipeline.php:149, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure}()
Pipeline.php:53, Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}()
Pipeline.php:102, Illuminate\Routing\Pipeline->then()
Router.php:660, October\Rain\Router\CoreRouter->runRouteWithinStack()
Router.php:635, October\Rain\Router\CoreRouter->runRoute()
Router.php:601, October\Rain\Router\CoreRouter->dispatchToRoute()
CoreRouter.php:20, October\Rain\Router\CoreRouter->dispatch()
Kernel.php:176, October\Rain\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
Pipeline.php:30, Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}()
CheckForMaintenanceMode.php:46, Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle()
Pipeline.php:149, Illuminate\Routing\Pipeline->Illuminate\Pipeline\{closure}()
Pipeline.php:53, Illuminate\Routing\Pipeline->Illuminate\Routing\{closure}()
Pipeline.php:102, Illuminate\Routing\Pipeline->then()
Kernel.php:151, October\Rain\Foundation\Http\Kernel->sendRequestThroughRouter()
Kernel.php:116, October\Rain\Foundation\Http\Kernel->handle()
index.php:73, {main}()

As you can see, the 3rd party lib is called here

Markdown.php:87, October\Rain\Parse\Markdown->parseInternal()

Here's a screen of the place when the buggy lib facade is going to be called

image

Please, let me know if I should do something else;

@LukeTowers
Copy link
Contributor

That's perfect, thanks @amorphine. Has the proposed solution been submitted to the third party library as a PR?

@amorphine
Copy link
Author

@LukeTowers The patch is not mine and as I can see the author has not created a PR.
It breaks compatibility with libxml versions lower than 2.7.8 due to him using the constants appeared since 2.7.7 and 2.7.8 libxml versions - LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD So the possible solution looks like not the best one.

The last erusev's commit was made more than two years ago. Seems like he is not going to develop the library anymore.

According to the forks there are some people still trying to support the project. May be a propriate author can be found there.

@LukeTowers
Copy link
Contributor

@amorphine October extends the base class allowing for any required modifications to be made in-library. Could you add processTag() to the \October\Rain\Parse\Parsedown\Parsedown class and do some debugging in there to find out why exactly the exact error message is being shown?

I'll note that the fix proposed is no longer the recommended one and seems to cause issues with 2.9. https://stackoverflow.com/questions/29493678/loadhtml-libxml-html-noimplied-on-an-html-fragment-generates-incorrect-tags

@amorphine
Copy link
Author

@LukeTowers I tested the code with different php implementations and it seems to be the problem affects only with the alpine distribution shipped with docker image.
I opened a duscussion with the authors
Let's wait what they say. I'll inform you.

@amorphine
Copy link
Author

amorphine commented May 21, 2018

@LukeTowers php-alpine docker image vendors say they can not help. I think the issue should be closed coz it's upon 3rd party, not October itself. Thanks.

docker-library/php#612

@LukeTowers
Copy link
Contributor

Alright, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants