Escape special characters in file paths when attaching files
This commit is contained in:
parent
41e2f3008e
commit
82448c4a4d
2 changed files with 16 additions and 1 deletions
|
@ -43,6 +43,21 @@ Zotero.File = new function(){
|
|||
this.getCharsetFromFile = getCharsetFromFile;
|
||||
this.addCharsetListener = addCharsetListener;
|
||||
|
||||
/**
|
||||
* Encode special characters in file paths that might cause problems,
|
||||
* like # (but preserve slashes or colons)
|
||||
*
|
||||
* @param {String} path File path
|
||||
* @return {String} Encoded file path
|
||||
*/
|
||||
this.encodeFilePath = function(path) {
|
||||
var parts = path.split(/([\\\/:]+)/);
|
||||
// Every other item is the separator
|
||||
for (var i=0, n=parts.length; i<n; i+=2) {
|
||||
parts[i] = encodeURIComponent(parts[i]);
|
||||
}
|
||||
return parts.join('');
|
||||
}
|
||||
|
||||
function getExtension(file){
|
||||
var pos = file.leafName.lastIndexOf('.');
|
||||
|
|
|
@ -291,7 +291,7 @@ Zotero.Translate.ItemSaver.prototype = {
|
|||
var IOService = Components.classes["@mozilla.org/network/io-service;1"].
|
||||
getService(Components.interfaces.nsIIOService);
|
||||
try {
|
||||
var uri = IOService.newURI(path, "", this._baseURI);
|
||||
var uri = IOService.newURI(Zotero.File.encodeFilePath(path), "", this._baseURI);
|
||||
}
|
||||
catch (e) {
|
||||
var msg = "Error parsing attachment path: " + path;
|
||||
|
|
Loading…
Reference in a new issue