opentbs icon indicating copy to clipboard operation
opentbs copied to clipboard

Random XML rendering (blip/embed)

Open matll42 opened this issue 6 years ago • 3 comments

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

matll42 avatar Sep 10 '18 16:09 matll42

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

Skrol29 avatar Sep 10 '18 20:09 Skrol29

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

matll42 avatar Sep 12 '18 13:09 matll42

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);

matll42 avatar Nov 06 '18 10:11 matll42