www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 50e100ec823825c54ccb78a43efdea4f74978786
parent 7f70af0c1ffefd865375ac9d6370f35bb8021f41
Author: Dan Stillman <dstillman@zotero.org>
Date:   Mon,  8 Feb 2010 17:56:43 +0000

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)


Diffstat:
Mchrome/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 @@ -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);