server_opensave-related changes: 1) Be more lenient in filename possibilities for server_opensave (supporting Unicode except characters disallowed in Windows file names); 2) XHTML escape filename and SVG content when put into HTML hidden input element as opposed to unnecessary URL-encoding; 3) fix base64 encoding (with update to dependent utf8-encoding function)--old base64 code caused SVG to break with surrogate pairs (e.g., in title); 4) provide default UTF-8 encoding in XML declaration and add this XML declaration to the download attribute as well
git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2662 eee81c28-f429-11dd-99c0-75d572ba1ddd
This commit is contained in:
@@ -13,7 +13,11 @@ svgEditor.addExtension("server_opensave", {
|
||||
'use strict';
|
||||
function getFileNameFromTitle () {
|
||||
var title = svgCanvas.getDocumentTitle();
|
||||
return $.trim(title).replace(/[^a-z0-9\.\_\-]+/gi, '_');
|
||||
// We convert (to underscore) only those disallowed Win7 file name characters
|
||||
return $.trim(title).replace(/[\/\\:*?"<>|]/g, '_');
|
||||
}
|
||||
function xhtmlEscape(str) {
|
||||
return str.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<'); // < is actually disallowed above anyways
|
||||
}
|
||||
function clientDownloadSupport (filename, suffix, uri) {
|
||||
var a,
|
||||
@@ -34,20 +38,20 @@ svgEditor.addExtension("server_opensave", {
|
||||
$('<iframe name="output_frame" src="#"/>').hide().appendTo('body');
|
||||
svgEditor.setCustomHandlers({
|
||||
save: function(win, data) {
|
||||
var svg = "<?xml version=\"1.0\"?>\n" + data,
|
||||
var svg = '<?xml version="1.0" encoding="UTF-8"?>\n' + data, // Firefox doesn't seem to know it is UTF-8 (if we skip the clientDownload code) despite the Content-Disposition header containing UTF-8, but adding the encoding works
|
||||
filename = getFileNameFromTitle();
|
||||
|
||||
//if (clientDownloadSupport(filename, '.svg', 'data:image/svg+xml,' + encodeURI(data))) { // Firefox limits size of file
|
||||
if (clientDownloadSupport(filename, '.svg', 'data:image/svg+xml;base64,' + svgedit.utilities.encode64(data))) {
|
||||
// if (clientDownloadSupport(filename, '.svg', 'data:image/svg+xml,' + encodeURI(data))) { // Firefox limits size of file
|
||||
if (clientDownloadSupport(filename, '.svg', 'data:image/svg+xml;base64,' + svgedit.utilities.encode64(svg))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$('<form>').attr({
|
||||
method: 'post',
|
||||
action: save_svg_action,
|
||||
target: 'output_frame'
|
||||
}) .append('<input type="hidden" name="output_svg" value="' + encodeURI(svg) + '">')
|
||||
.append('<input type="hidden" name="filename" value="' + filename + '">')
|
||||
}).append('<input type="hidden" name="output_svg" value="' + xhtmlEscape(svg) + '">')
|
||||
.append('<input type="hidden" name="filename" value="' + xhtmlEscape(filename) + '">')
|
||||
.appendTo('body')
|
||||
.submit().remove();
|
||||
},
|
||||
@@ -70,8 +74,8 @@ svgEditor.addExtension("server_opensave", {
|
||||
uiStrings = svgEditor.uiStrings,
|
||||
note = '';
|
||||
|
||||
// Check if there's issues
|
||||
if(issues.length) {
|
||||
// Check if there are issues
|
||||
if (issues.length) {
|
||||
pre = "\n \u2022 ";
|
||||
note += ("\n\n" + pre + issues.join(pre));
|
||||
}
|
||||
@@ -91,9 +95,9 @@ svgEditor.addExtension("server_opensave", {
|
||||
method: 'post',
|
||||
action: save_img_action,
|
||||
target: 'output_frame'
|
||||
}) .append('<input type="hidden" name="output_img" value="' + datauri + '">')
|
||||
}).append('<input type="hidden" name="output_img" value="' + datauri + '">')
|
||||
.append('<input type="hidden" name="mime" value="' + mimeType + '">')
|
||||
.append('<input type="hidden" name="filename" value="' + filename + '">')
|
||||
.append('<input type="hidden" name="filename" value="' + xhtmlEscape(filename) + '">')
|
||||
.appendTo('body')
|
||||
.submit().remove();
|
||||
}});
|
||||
@@ -103,7 +107,7 @@ svgEditor.addExtension("server_opensave", {
|
||||
});
|
||||
|
||||
// Do nothing if client support is found
|
||||
if(window.FileReader) {return;}
|
||||
if (window.FileReader) {return;}
|
||||
|
||||
// Change these to appropriate script file
|
||||
open_svg_action = 'extensions/fileopen.php?type=load_svg';
|
||||
@@ -113,7 +117,7 @@ svgEditor.addExtension("server_opensave", {
|
||||
// Set up function for PHP uploader to use
|
||||
svgEditor.processFile = function(str64, type) {
|
||||
var xmlstr;
|
||||
if(cancelled) {
|
||||
if (cancelled) {
|
||||
cancelled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user