From 50e100ec823825c54ccb78a43efdea4f74978786 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 8 Feb 2010 17:56:43 +0000 Subject: [PATCH] Stored files with '%' in filename couldn't be found on Windows -- now, on all platforms, filter imported filename (after first trying to URL decode, just to be nice) --- chrome/content/zotero/xpcom/attachments.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index e5ac91a1f..13d3c94a9 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -49,10 +49,16 @@ Zotero.Attachments = new function(){ function importFromFile(file, sourceItemID, libraryID) { Zotero.debug('Importing attachment from file'); - var title = file.leafName; + // Try decoding URI entities, since we're going to strip '%' + var newName = file.leafName; + try { + newName = decodeURIComponent(file.leafName); + } + catch (e) {} + newName = Zotero.File.getValidFileName(newName); if (!file.isFile()) { - throw ("'" + title + "' must be a file in Zotero.Attachments.importFromFile()"); + throw ("'" + file.leafName + "' must be a file in Zotero.Attachments.importFromFile()"); } Zotero.DB.beginTransaction(); @@ -67,7 +73,7 @@ Zotero.Attachments = new function(){ else if (libraryID) { attachmentItem.libraryID = libraryID; } - attachmentItem.setField('title', title); + attachmentItem.setField('title', newName); attachmentItem.setSource(sourceItemID); attachmentItem.attachmentLinkMode = this.LINK_MODE_IMPORTED_FILE; var itemID = attachmentItem.save(); @@ -75,11 +81,11 @@ Zotero.Attachments = new function(){ // Create directory for attachment files within storage directory var destDir = this.createDirectoryForItem(itemID); - file.copyTo(destDir, null); + file.copyTo(destDir, newName); // Point to copied file var newFile = destDir.clone(); - newFile.append(title); + newFile.append(newName); var mimeType = Zotero.MIME.getMIMETypeFromFile(newFile);