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

Ampersands Cause Unterminated Entity Reference error #14

Closed
rjcdr opened this issue Sep 2, 2019 · 2 comments
Closed

Ampersands Cause Unterminated Entity Reference error #14

rjcdr opened this issue Sep 2, 2019 · 2 comments

Comments

@rjcdr
Copy link

rjcdr commented Sep 2, 2019

When ampersands (& or &) are included in the image caption/title, a reference error is thrown. Details follow:

Here's an example of markdown that triggers the error:

![](9-Sanford-Biggers-2016_BAM-for-Sandra_HD-video_edition-of-3_1-minute-13-seconds.jpg?classes=caption "Sanford & Biggers. “BAM (for Sandra),” 2016. HD video, 1 minute 13 seconds.")

Screen Shot 2019-09-02 at 00 07 14

/var/www/html/hb-grav/user/plugins/image-captions/vendor/imangazaliev/didom/src/DiDom/Element.php

        /**
         * Set the value of this node.
         *
         * @param string $value The new value of the node
         *
         * @return \DiDom\Element
         *
         * @throws \InvalidArgumentException if value is not string
         */
        public function setValue($value)
        {
            if (is_numeric($value)) {
                $value = (string) $value;
            }
     
            if (!is_string($value) && $value !== null) {
                throw new InvalidArgumentException(sprintf('%s expects parameter 1 to be string, %s given', __METHOD__, (is_object($value) ? get_class($value) : gettype($value))));
            }
     
            $this->node->nodeValue = $value;
     
            return $this;
        }
     
        /**
         * Returns true if current node is a DOMElement instance.
         *
         * @return bool
         */
        public function isElementNode()
        {
            return $this->node instanceof DOMElement;
        }
     
        /**
         * Returns true if current node is a a DOMText instance.
         *
         * @return bool
         */
        public function isTextNode()

Arguments

    "DiDom\Element::setValue(): unterminated entity reference  Biggers. “BAM (for Sandra),” 2016. HD video, 1 minute 13 seconds."

Whoops\Exception\ErrorException thrown with message "DiDom\Element::setValue(): unterminated entity reference Biggers. “BAM (for Sandra),” 2016. HD video, 1 minute 13 seconds."

Stacktrace:
#62 Whoops\Exception\ErrorException in /var/www/html/hb-grav/user/plugins/image-captions/vendor/imangazaliev/didom/src/DiDom/Element.php:772
#61 Grav\Common\Debugger:deprecatedErrorHandler in /var/www/html/hb-grav/user/plugins/image-captions/vendor/imangazaliev/didom/src/DiDom/Element.php:772
#60 DiDom\Element:setValue in /var/www/html/hb-grav/user/plugins/image-captions/vendor/imangazaliev/didom/src/DiDom/Element.php:57
#59 DiDom\Element:__construct in /var/www/html/hb-grav/user/plugins/image-captions/image-captions.php:129
#58 Grav\Plugin\ImageCaptionsPlugin:processFigures in /var/www/html/hb-grav/user/plugins/image-captions/image-captions.php:82
#57 Grav\Plugin\ImageCaptionsPlugin:onPageContentProcessed in /var/www/html/hb-grav/vendor/symfony/event-dispatcher/EventDispatcher.php:212
#56 Symfony\Component\EventDispatcher\EventDispatcher:doDispatch in /var/www/html/hb-grav/vendor/symfony/event-dispatcher/EventDispatcher.php:44
#55 Symfony\Component\EventDispatcher\EventDispatcher:dispatch in /var/www/html/hb-grav/vendor/rockettheme/toolbox/Event/src/EventDispatcher.php:23
#54 RocketTheme\Toolbox\Event\EventDispatcher:dispatch in /var/www/html/hb-grav/system/src/Grav/Common/Grav.php:365
#53 Grav\Common\Grav:fireEvent in /var/www/html/hb-grav/system/src/Grav/Common/Page/Page.php:729
#52 Grav\Common\Page\Page:content in /var/www/html/hb-grav/system/src/Grav/Common/Twig/Twig.php:366
#51 Grav\Common\Twig\Twig:processSite in /var/www/html/hb-grav/system/src/Grav/Common/Service/OutputServiceProvider.php:28
#50 Grav\Common\Service\OutputServiceProvider:Grav\Common\Service{closure} in /var/www/html/hb-grav/vendor/pimple/pimple/src/Pimple/Container.php:118
#49 Pimple\Container:offsetGet in /var/www/html/hb-grav/system/src/Grav/Common/Processors/RenderProcessor.php:28
#48 Grav\Common\Processors\RenderProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#47 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#46 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/DebuggerAssetsProcessor.php:28
#45 Grav\Common\Processors\DebuggerAssetsProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#44 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#43 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/PagesProcessor.php:69
#42 Grav\Common\Processors\PagesProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#41 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#40 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/TwigProcessor.php:27
#39 Grav\Common\Processors\TwigProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#38 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#37 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/AssetsProcessor.php:28
#36 Grav\Common\Processors\AssetsProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#35 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#34 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/SchedulerProcessor.php:29
#33 Grav\Common\Processors\SchedulerProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#32 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#31 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/BackupsProcessor.php:28
#30 Grav\Common\Processors\BackupsProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#29 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#28 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/TasksProcessor.php:59
#27 Grav\Common\Processors\TasksProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#26 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#25 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/RequestProcessor.php:52
#24 Grav\Common\Processors\RequestProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#23 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#22 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/ThemesProcessor.php:27
#21 Grav\Common\Processors\ThemesProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#20 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#19 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/PluginsProcessor.php:30
#18 Grav\Common\Processors\PluginsProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#17 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#16 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/InitializeProcessor.php:78
#15 Grav\Common\Processors\InitializeProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#14 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#13 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/DebuggerProcessor.php:27
#12 Grav\Common\Processors\DebuggerProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#11 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#10 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/ErrorsProcessor.php:27
#9 Grav\Common\Processors\ErrorsProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#8 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#7 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/LoggerProcessor.php:48
#6 Grav\Common\Processors\LoggerProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#5 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#4 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Processors/ConfigurationProcessor.php:28
#3 Grav\Common\Processors\ConfigurationProcessor:process in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:45
#2 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php:57
#1 Grav\Framework\RequestHandler\RequestHandler:handle in /var/www/html/hb-grav/system/src/Grav/Common/Grav.php:249
#0 Grav\Common\Grav:process in /var/www/html/hb-grav/index.php:53

@rjcdr rjcdr changed the title Ampersands Cause javascript reference error Ampersands Cause Unterminated Entity Reference error Sep 2, 2019
@rhukster
Copy link
Member

rhukster commented Dec 4, 2021

Just found a workaround for this.. use a & not just & then it works fine.

@rhukster rhukster closed this as completed Dec 4, 2021
@NoNoNo
Copy link

NoNoNo commented Jun 14, 2024

This works for me:

$figcaption = new Element('figcaption', null, ['class' => $figcaption_class]);
$figcaption->appendChild($document->createTextNode($caption));

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

No branches or pull requests

3 participants