lincolnloop / python-qrcode

Python QR Code image generator
https://pypi.python.org/pypi/qrcode
Other
4.39k stars 673 forks source link

GeneratedSVG is invalid in HTML #317

Open xi opened 1 year ago

xi commented 1 year ago

Since 7.4 the generated SVG looks like this:

<svg width="45mm" height="45mm" version="1.1" xmlns="http://www.w3.org/2000/svg">
  <svg:rect xmlns:svg="http://www.w3.org/2000/svg" x="4mm" y="4mm" width="1mm" height="1mm" fill="#000"></svg:rect>
  …
</svg>

Note the namespace on the rect element. This is not only unnecessary, it is even invalid when used inline with HTML

The HTML syntax does not support namespace declarations -- https://html.spec.whatwg.org/multipage/syntax.html#elements-2

As far as I can tell this was introduced in 2287382. Before that, SvgFragmentImage._rect() used a namespaced tag by default, but SvgImage._rect() overwrote that to use a non-namespaced tag. Since 2287382, SvgSquareDrawer.drawrect() is used in both cases, which always uses a namespaced tag.

leveraction commented 1 year ago

Same problem. "<rect " has become "<svg:rect" and this results in my qr code svg image coming out as a white square where it used to work. Reverting back to 7.3.1 in the meantime.