jsreport / jsreport-docx

jsreport recipe rendering word docx
MIT License
10 stars 3 forks source link

Scope changes render behaviour of images #6

Closed sebastian-schlecht closed 4 years ago

sebastian-schlecht commented 4 years ago

Hey, while integrating the URL change, I noticed something odd. It seem as the scope of variables causes picture to not be rendered. This is the issue for both url based sources, as well as base64 encoded images.

Example templates: image-n.docx

Render the template above using latest master and the following sample data:

   {
        "arr": [1, 2],
        "src": "http://cdn.osxdaily.com/wp-content/themes/osxdaily-left2/img/osxdaily-logo-l.png"
    }

The result is supposed to contain the image at the url, three times, yet the first render (outermost scope) does not replace the placeholder - instead the serialised JSON is present in the tooltip. The images within the loop render fine. Changing src to base64 does not change the result.

Any thoughts? Am I missing anything here?

sebastian-schlecht commented 4 years ago

I debugged it for a few minutes and found out that some optimisations that were introduced a while back are using regexes now instead of XML tree ops. I suspect there is a bug in the regex that causes to break under certain conditions, i.e. if the description of the image in the word file has a line break (as the test image does).

A different regex eliminates the pains there: https://regex101.com/r/iHSTON/1/

pofider commented 4 years ago

Thank you. Your PR https://github.com/jsreport/jsreport-docx/pull/7 is merged