commit ecaa599bec32e999dbbbdef1a433295955856629
parent af3ef422a39110ece6647d5215971458cc03848a
Author: Dan Stillman <dstillman@zotero.org>
Date: Sun, 13 Dec 2009 04:14:31 +0000
- Renaming an attachment file with certain extended characters could cause it to be deleted
- When relinking a file, automatically rename file with cross-platform invalid characters (e.g., "/") filtered out
Diffstat:
2 files changed, 25 insertions(+), 6 deletions(-)
diff --git a/chrome/content/zotero/bindings/attachmentbox.xml b/chrome/content/zotero/bindings/attachmentbox.xml
@@ -409,7 +409,11 @@
if (checkState.value) {
var renamed = item.renameAttachmentFile(newTitle.value);
if (renamed == -1) {
- var confirmed = confirm(newTitle.value + ' exists. Overwrite existing file?');
+ var confirmed = nsIPS.confirm(
+ window,
+ '',
+ newTitle.value + ' exists. Overwrite existing file?'
+ );
if (confirmed) {
item.renameAttachmentFile(newTitle.value, true);
break;
diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js
@@ -2592,15 +2592,18 @@ Zotero.Item.prototype.renameAttachmentFile = function(newName, overwrite) {
try {
newName = Zotero.File.getValidFileName(newName);
- if (file.leafName == newName) {
- return true;
- }
-
var dest = file.parent;
dest.append(newName);
+ // Ignore if no change
+ //
+ // Note: Just comparing file.leafName to newName isn't reliable
+ if (file.leafName == dest.leafName) {
+ return true;
+ }
+
if (overwrite) {
- dest.remove(null);
+ dest.remove(false);
}
else if (dest.exists()) {
return -1;
@@ -2635,9 +2638,21 @@ Zotero.Item.prototype.relinkAttachmentFile = function(file) {
throw('Cannot relink linked URL in Zotero.Items.relinkAttachmentFile()');
}
+ var newName = Zotero.File.getValidFileName(file.leafName);
+ if (!newName) {
+ throw ("No valid characters in filename after filtering in Zotero.Item.relinkAttachmentFile()");
+ }
+
+ // Rename file to filtered name if necessary
+ if (file.leafName != newName) {
+ Zotero.debug("Renaming file '" + file.leafName + "' to '" + newName + "'");
+ file.moveTo(null, newName);
+ }
+
var path = Zotero.Attachments.getPath(file, linkMode);
this.attachmentPath = path;
this.save();
+ return false;
}