Commit 19315f4b authored by S Anand's avatar S Anand

BUG: if XML contains invalid characters, strip them out before downloading

parent 8e9827f9
......@@ -68,6 +68,12 @@ function svgize(node) {
return node
}
// XML 1.0 only allows certain characters. Ignore the rest
// http://stackoverflow.com/a/28152666/100904
function xml_escape(s) {
return s.replace(/[^\x09\x0a\x0d\u0020-\ud7ff\ue000-\ufffd\u10000-\u10ffff]/g, '')
}
let download = function(options) {
var mime = options.mime,
source = options.source,
......@@ -80,7 +86,7 @@ let download = function(options) {
node = svgize($(options.svg).get(0))
if (!source) {
source = (new XMLSerializer()).serializeToString(node)
source = xml_escape((new XMLSerializer()).serializeToString(node))
if (!options.nostyle) {
sheets = document.styleSheets || []
......@@ -106,7 +112,7 @@ let download = function(options) {
node.setAttribute('width', node.getBoundingClientRect().width)
img = new Image()
source = (new XMLSerializer()).serializeToString(node)
source = xml_escape((new XMLSerializer()).serializeToString(node))
blob = new Blob([source], {type : 'image/svg+xml;charset=utf-8'})
url = URL.createObjectURL(blob)
img.onload = function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment