Minor clean-up; UTF-8 for SVG

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2667 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Brett Zamir 2014-02-02 01:06:25 +00:00
parent a5083f0394
commit 1181de6847
4 changed files with 10 additions and 10 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
$allowedMimeTypesBySuffix = array( $allowedMimeTypesBySuffix = array(
'svg' => 'image/svg+xml', 'svg' => 'image/svg+xml;charset=utf-8',
'png' => 'image/png', 'png' => 'image/png',
'jpeg' => 'image/jpeg', 'jpeg' => 'image/jpeg',
'bmp' => 'image/bmp', 'bmp' => 'image/bmp',

View File

@ -38,11 +38,10 @@ svgEditor.addExtension("server_opensave", {
$('<iframe name="output_frame" src="#"/>').hide().appendTo('body'); $('<iframe name="output_frame" src="#"/>').hide().appendTo('body');
svgEditor.setCustomHandlers({ svgEditor.setCustomHandlers({
save: function(win, data) { save: function(win, 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 var svg = '<?xml version="1.0" encoding="UTF-8"?>\n' + data, // Firefox doesn't seem to know it is UTF-8 (no matter whether we use or skip the clientDownload code) despite the Content-Disposition header containing UTF-8, but adding the encoding works
filename = getFileNameFromTitle(); 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;charset=UTF-8;base64,' + svgedit.utilities.encode64(svg))) {
if (clientDownloadSupport(filename, '.svg', 'data:image/svg+xml;base64,' + svgedit.utilities.encode64(svg))) {
return; return;
} }
@ -105,7 +104,7 @@ svgEditor.addExtension("server_opensave", {
} }
}); });
// Do nothing if client support is found // Do nothing if client support is found
if (window.FileReader) {return;} if (window.FileReader) {return;}
@ -159,7 +158,7 @@ svgEditor.addExtension("server_opensave", {
// Create image form // Create image form
import_img_form = open_svg_form.clone().attr('action', import_img_action); import_img_form = open_svg_form.clone().attr('action', import_img_action);
// It appears necessory to rebuild this input every time a file is // It appears necessary to rebuild this input every time a file is
// selected so the same file can be picked and the change event can fire. // selected so the same file can be picked and the change event can fire.
function rebuildInput(form) { function rebuildInput(form) {
form.empty(); form.empty();

View File

@ -25,7 +25,7 @@
$prefix = ''; $prefix = '';
// Make Data URL prefix for import image // Make Data URL prefix for import image
if($type == 'import_img') { if ($type == 'import_img') {
$info = getimagesize($file); $info = getimagesize($file);
if (!in_array($info['mime'], $allowedMimeTypesBySuffix)) { if (!in_array($info['mime'], $allowedMimeTypesBySuffix)) {
exit; exit;
@ -37,7 +37,8 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<script> <script>
window.top.window.svgEditor.processFile("<?php
top.svgEditor.processFile("<?php
// This should be safe since SVG edit does its own filtering (e.g., if an SVG file contains scripts) // This should be safe since SVG edit does its own filtering (e.g., if an SVG file contains scripts)
echo $prefix . base64_encode($output); echo $prefix . base64_encode($output);

View File

@ -20,7 +20,7 @@ function encodeRFC5987ValueChars ($str) {
require('allowedMimeTypes.php'); require('allowedMimeTypes.php');
$mime = !isset($_POST['mime']) || !in_array($_POST['mime'], $allowedMimeTypesBySuffix) ? 'image/svg+xml' : $_POST['mime']; $mime = !isset($_POST['mime']) || !in_array($_POST['mime'], $allowedMimeTypesBySuffix) ? 'image/svg+xml;charset=UTF-8' : $_POST['mime'];
if (!isset($_POST['output_svg']) && !isset($_POST['output_img'])) { if (!isset($_POST['output_svg']) && !isset($_POST['output_img'])) {
die('post fail'); die('post fail');
@ -52,7 +52,7 @@ header("Content-Disposition: attachment; filename*=UTF-8''" . encodeRFC5987Value
// preg_replace('@[\\\\/:*?"<>|]@', '', $file) // If we wanted to strip Windows-disallowed characters server-side (but not a security issue, so we can strip client-side instead) // preg_replace('@[\\\\/:*?"<>|]@', '', $file) // If we wanted to strip Windows-disallowed characters server-side (but not a security issue, so we can strip client-side instead)
$file $file
)); ));
header("Content-Type: " . $mime . ';charset=utf-8'); header("Content-Type: " . $mime);
header("Content-Transfer-Encoding: binary"); header("Content-Transfer-Encoding: binary");
echo $contents; echo $contents;