Pikchr

Invalid SVG for lone Ampersand
Login

Invalid SVG for lone Ampersand

(1) By Venks I (venksi) on 2021-12-24 03:56:03 [source]

I hit a problem with the generated SVG not being readable. Here's a small example:

Input:

box "A" "&" "B"

Output:

<svg xmlns='http://www.w3.org/2000/svg' class="pikchr" viewBox="0 0 112.32 76.32">
<style type="text/css">text{font-size:11pt;font-family:Helvetica}</style>
<path d="M2,74L110,74L110,2L2,2Z"  style="fill:none;stroke-width:2.16;stroke:rgb(0,0,0);" />
<text x="56" y="18" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">A</text>
<text x="56" y="38" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">&</text>
<text x="56" y="58" text-anchor="middle" fill="rgb(0,0,0)" dominant-baseline="central">B</text>
</svg>

I think the lone & in the 3rd last line should've been converted to &amp; At least one of the readers I have dies on this svg.

I have seen other entities being generated correctly, so this seems to be some corner case.

Thanks

Venks

(2) By Stephan Beal (stephan) on 2021-12-24 04:10:38 in reply to 1 [link] [source]

I think the lone & in the 3rd last line should've been converted to & At least one of the readers I have dies on this svg.

i've patched this in the current trunk and hopefully haven't introduced undesired side effects by doing so. Please try it out and let us know if it works for you. Your sample input behaves as expected for me with this patch, escaping the ampersand.

(3) By Venks I (venksi) on 2021-12-24 05:33:18 in reply to 2 [link] [source]

Thanks for the quick turnaround Stephan. Works fine for me now.