Skrol29 / opentbs

With OpenTBS you can merge OpenOffice - LibreOffice and Ms Office documents with PHP using the TinyButStrong template engine. Simple use OpenOffice - LibreOffice or Ms Office to edit your templates : DOCX, XLSX, PPTX, ODT, OSD, ODP and other formats. That is the Natural Template philosophy.
http://www.tinybutstrong.com/opentbs.php
70 stars 17 forks source link

Random XML rendering (blip/embed) #6

Open matll42 opened 6 years ago

matll42 commented 6 years ago

Hello,

Thanks again for sharing your Library. I'm embedding images on a Word (docx) document and I'm actually facing a strange issue. There are somes XML attributes that are html encoded and some not.

On a file with 23 embed attributes, 2 are wrong like this one

<a:blip r:embed=&quot;rId12" cstate="print">

Other are corrects like the Following :

<a:blip r:embed="rId12" cstate="print">

When I checked function that generate this line, the quote symbol is correct

// phpdocx/classes/CreateElement.php:180
protected function generateBLIP($cstate = 'print')
    {
        $xml = '<' . CreateImage::NAMESPACEWORD1 .
                ':blip r:embed="rId' . $this->getRId() .
                '" cstate="' . $cstate .
                '"></' . CreateImage::NAMESPACEWORD1 .
                ':blip>__GENERATEBLIPFILL__';

        $this->_xml = str_replace('__GENERATEBLIPFILL__', $xml, $this->_xml);
    }

Did I do something wrong?

Version used: 3.10.1 PHP: 5.5.9 & 7.2.7

Skrol29 commented 6 years ago

I cannot see how OpenTBS could have changed this character. Can you provide a snippet that reproduces the problem ?

matll42 commented 6 years ago

I'll try to make a minimal example, but it's a 20 pages document generated by a WordPress database.

matll42 commented 6 years ago

It appears that we had a "&" in some textual content that was not escaped. And & is a reserved character in XML. As soon as we escaped it on content, the problem on the attribute disappears.

$string = str_replace('&', '&amp; ', $string);