Fix XML escaping problem in attributes, add unit test
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@1400 eee81c28-f429-11dd-99c0-75d572ba1dddmaster
parent
19d9998743
commit
469868d731
|
@ -1530,7 +1530,7 @@ function BatchCommand(text) {
|
||||||
var i = attrs.length;
|
var i = attrs.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
attr = attrs.item(i);
|
attr = attrs.item(i);
|
||||||
var attrVal = attr.nodeValue;
|
var attrVal = toXml(attr.nodeValue);
|
||||||
// only serialize attributes we don't use internally
|
// only serialize attributes we don't use internally
|
||||||
if (attrVal != "" &&
|
if (attrVal != "" &&
|
||||||
$.inArray(attr.localName, ['width','height','xmlns','x','y','viewBox','id','overflow']) == -1)
|
$.inArray(attr.localName, ['width','height','xmlns','x','y','viewBox','id','overflow']) == -1)
|
||||||
|
@ -1545,7 +1545,7 @@ function BatchCommand(text) {
|
||||||
} else {
|
} else {
|
||||||
for (var i=attrs.length-1; i>=0; i--) {
|
for (var i=attrs.length-1; i>=0; i--) {
|
||||||
attr = attrs.item(i);
|
attr = attrs.item(i);
|
||||||
var attrVal = attr.nodeValue;
|
var attrVal = toXml(attr.nodeValue);
|
||||||
if (attr.localName == '-moz-math-font-style') continue;
|
if (attr.localName == '-moz-math-font-style') continue;
|
||||||
if (attrVal != "") {
|
if (attrVal != "") {
|
||||||
if(attrVal.indexOf('pointer-events') == 0) continue;
|
if(attrVal.indexOf('pointer-events') == 0) continue;
|
||||||
|
|
|
@ -172,7 +172,7 @@
|
||||||
'</svg>');
|
'</svg>');
|
||||||
var attrVal = document.getElementById('se_test_elem').getAttributeNS("http://svg-edit.googlecode.com", "foo");
|
var attrVal = document.getElementById('se_test_elem').getAttributeNS("http://svg-edit.googlecode.com", "foo");
|
||||||
|
|
||||||
equals(true, attrVal === "bar", "Preserved namespaced attribute on import");
|
equals(attrVal === "bar", true, "Preserved namespaced attribute on import");
|
||||||
|
|
||||||
var output = svgCanvas.getSvgString();
|
var output = svgCanvas.getSvgString();
|
||||||
var has_xlink = output.indexOf('xmlns:xlink="http://www.w3.org/1999/xlink"') !== -1;
|
var has_xlink = output.indexOf('xmlns:xlink="http://www.w3.org/1999/xlink"') !== -1;
|
||||||
|
@ -180,14 +180,38 @@
|
||||||
var has_foo = output.indexOf('xmlns:foo=') === -1;
|
var has_foo = output.indexOf('xmlns:foo=') === -1;
|
||||||
var has_attr = output.indexOf('se:foo="bar"') !== -1;
|
var has_attr = output.indexOf('se:foo="bar"') !== -1;
|
||||||
|
|
||||||
equals(true, has_attr, "Preserved namespaced attribute on export");
|
equals(has_attr, true, "Preserved namespaced attribute on export");
|
||||||
equals(true, has_xlink, "Included xlink: xmlns");
|
equals(has_xlink, true, "Included xlink: xmlns");
|
||||||
equals(true, has_se, "Included se: xmlns");
|
equals(has_se, true, "Included se: xmlns");
|
||||||
equals(true, has_foo, "Did not include foo: xmlns");
|
equals(has_foo, true, "Did not include foo: xmlns");
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("Test import math elements inside a foreignObject", function() {
|
||||||
|
expect(2);
|
||||||
|
var set = svgCanvas.setSvgString('<svg width="640" height="480" xmlns="http://www.w3.org/2000/svg" xmlns:se="http://svg-edit.googlecode.com" xmlns:xlink="http://www.w3.org/1999/xlink" class="foo">'+
|
||||||
|
'<foreignObject id="fo" y="0" x="0" width="24" height="26" font-size="24">'+
|
||||||
|
'<math id="math" display="inline" xmlns="http://www.w3.org/1998/Math/MathML">'+
|
||||||
|
'<msub>'+
|
||||||
|
'<mi>A</mi>'+
|
||||||
|
'<mn>0</mn>'+
|
||||||
|
'</msub>'+
|
||||||
|
'</math>'+
|
||||||
|
'</foreignObject>'+
|
||||||
|
'</svg>');
|
||||||
|
var math = document.getElementById('math');
|
||||||
|
|
||||||
|
equals(!!math, true, "Math element exists");
|
||||||
|
equals(math.namespaceURI, "http://www.w3.org/1998/Math/MathML", "Preserved MathML namespace");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("Test XML entities in attribute", function() {
|
||||||
|
expect(3);
|
||||||
|
|
||||||
|
equals(svgCanvas.getPrivateMethods().toXml("<"), "<", "Escaped < properly");
|
||||||
|
equals(svgCanvas.getPrivateMethods().toXml(">"), ">", "Escaped > properly");
|
||||||
|
equals(svgCanvas.getPrivateMethods().toXml("&"), "&", "Escaped & properly");
|
||||||
|
// TODO: what about " and ' ?
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
Loading…
Reference in New Issue