From fe04d60981dbb9a19f568a7e1873c4874d9ce129 Mon Sep 17 00:00:00 2001 From: aurimasv Date: Tue, 13 Nov 2012 03:06:50 -0600 Subject: [PATCH 01/12] Shorten long file names. Closes #8 --- chrome/content/zotero/webpagedump/common.js | 13 +++---- chrome/content/zotero/webpagedump/domsaver.js | 15 +++++--- chrome/content/zotero/xpcom/attachments.js | 19 +++++----- chrome/content/zotero/xpcom/file.js | 38 +++++++++++++++++-- 4 files changed, 58 insertions(+), 27 deletions(-) diff --git a/chrome/content/zotero/webpagedump/common.js b/chrome/content/zotero/webpagedump/common.js index b618eca021..673be0d9e3 100644 --- a/chrome/content/zotero/webpagedump/common.js +++ b/chrome/content/zotero/webpagedump/common.js @@ -54,6 +54,8 @@ var WPD_DEFAULTHEIGHT = 768; var WPD_MAXUIERRORCOUNT = 8; +// maximum character length for a valid file name (excluding extension) +var WPD_MAX_FILENAME_LENGTH = 100; /*function wpdGetTopBrowserWindow() { @@ -353,15 +355,10 @@ var wpdCommon = { }, // replace illegal characters + // and shorten long file names getValidFileName: function (aFileName) { - aFileName = aFileName.replace(/[\"\?!~`]+/g, ""); - aFileName = aFileName.replace(/[\*\&]+/g, "+"); - aFileName = aFileName.replace(/[\\\/\|\:;]+/g, "-"); - aFileName = aFileName.replace(/[\<]+/g, "("); - aFileName = aFileName.replace(/[\>]+/g, ")"); - aFileName = aFileName.replace(/[\s]+/g, "_"); - aFileName = aFileName.replace(/[%]+/g, "@"); - return aFileName; + aFileName = Zotero.File.getValidFileName(aFileName).toLowerCase(); + return Zotero.File.truncateFileName(aFileName, WPD_MAX_FILENAME_LENGTH); }, getURL: function () { diff --git a/chrome/content/zotero/webpagedump/domsaver.js b/chrome/content/zotero/webpagedump/domsaver.js index d93d4243b8..41fb8f5b63 100644 --- a/chrome/content/zotero/webpagedump/domsaver.js +++ b/chrome/content/zotero/webpagedump/domsaver.js @@ -164,7 +164,8 @@ var wpdDOMSaver = { // Split fileName in Path and Name - this.name = wpdCommon.getFileLeafName(fileName); // extract fileName from filePath + this.name = wpdCommon.getValidFileName( + wpdCommon.getFileLeafName(fileName)); // extract fileName from filePath this.currentDir = wpdCommon.getFilePath(fileName); // only directory this.name = wpdCommon.splitFileName(this.name)[0]; // no extension! @@ -221,7 +222,7 @@ var wpdDOMSaver = { // resolve the javascript links inside the attributes (e.g. onclick,...) normalizeJavaScriptLink: function (aNode, aAttr) { var val = aNode.getAttribute(aAttr); // get the attribute value and check for link stuff - if (!val.match(/\(\'([^\']+)\'/)) return aNode; + if (!val || !val.match(/\(\'([^\']+)\'/)) return aNode; val = RegExp.$1; if (val.indexOf("/") == -1 && val.indexOf(".") == -1) return aNode; val = wpdCommon.resolveURL(this.currentURL, val); // it is a link -> resolve and set the URL to the local URL @@ -409,9 +410,12 @@ var wpdDOMSaver = { case "link": // could containt urls (icon, stylesheet and fontdef) // We have to remove nodes with the stylesheet attribute because they will be added later - if ((aNode.getAttribute("rel").toLowerCase() == "stylesheet") && (aNode.getAttribute("href").indexOf("chrome://") == -1)) { + if(!aNode.hasAttribute("rel")) return aNode; + if (aNode.getAttribute("rel").toLowerCase() == "stylesheet" + && (aNode.hasAttribute("href") && aNode.getAttribute("href").indexOf("chrome://") == -1)) { return wpdCommon.removeNodeFromParent(aNode); - } else if ((aNode.getAttribute("rel").toLowerCase() == "shortcut icon") || (aNode.getAttribute("rel").toLowerCase() == "icon")) { + } else if (aNode.getAttribute("rel").toLowerCase() == "shortcut icon" + || aNode.getAttribute("rel").toLowerCase() == "icon") { var aFileName = this.download(aNode.href, true); // Changed by Dan S. for Zotero -- see this.repairRelativeLinks() if (aFileName) aNode.setAttribute("href", this.relativeLinkFix(aFileName)); @@ -730,7 +734,6 @@ var wpdDOMSaver = { // generate a filename var newFileName = aURL.fileName.toLowerCase(); if (!newFileName) newFileName = "untitled"; - newFileName = wpdCommon.getValidFileName(newFileName); // same name but different location? newFileName = this.getUniqueFileNameAndRegister(newFileName, aURLSpec); // is the file already registered (processed) ? @@ -1074,7 +1077,7 @@ var wpdDOMSaver = { // (be sure to call the init function at the top of this file before) saveHTMLDocument: function () { try { - this.saveDocumentEx(this.document, this.name); + return this.saveDocumentEx(this.document, this.name); } catch (ex) { wpdCommon.addError("[wpdDOMSaver.saveHTMLDocument]\n -> " + ex); } diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index a30bd0f3a0..687a284ee1 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -544,10 +544,12 @@ Zotero.Attachments = new function(){ var file = Components.classes["@mozilla.org/file/local;1"]. createInstance(Components.interfaces.nsILocalFile); file.initWithFile(destDir); - - var fileName = _getFileNameFromURL(url, mimeType); - file.append(fileName); - + + var fileName = Zotero.File.truncateFileName( + _getFileNameFromURL(url, mimeType).toLowerCase(), + 100); //make sure this matches WPD settings in webpagedump/common.js + file.append(fileName) + if (mimeType == 'application/pdf') { var f = function() { Zotero.Fulltext.indexPDF(file, itemID); @@ -575,10 +577,10 @@ Zotero.Attachments = new function(){ Components.classes["@mozilla.org/moz/jssubscript-loader;1"] .getService(Components.interfaces.mozIJSSubScriptLoader) .loadSubScript("chrome://zotero/content/webpagedump/domsaver.js", wpd); - + wpd.wpdDOMSaver.init(file.path, document); wpd.wpdDOMSaver.saveHTMLDocument(); - + attachmentItem.attachmentPath = this.getPath( file, Zotero.Attachments.LINK_MODE_IMPORTED_URL ); @@ -1171,10 +1173,7 @@ Zotero.Attachments = new function(){ nsIURL.fileBaseName = nsIURL.fileBaseName + '.' + tld; } - // Pass unencoded name to getValidFileName() so that '%20' isn't stripped to '20' - nsIURL.fileBaseName = Zotero.File.getValidFileName(decodeURIComponent(nsIURL.fileBaseName)); - - return decodeURIComponent(nsIURL.fileName); + return Zotero.File.getValidFileName(decodeURIComponent(nsIURL.fileName)); } diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 3051e730aa..375ba4a090 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -31,6 +31,7 @@ Zotero.File = new function(){ this.getContentsFromURL = getContentsFromURL; this.putContents = putContents; this.getValidFileName = getValidFileName; + this.truncateFileName = truncateFileName; this.copyToUnique = this.copyToUnique; this.getCharsetFromFile = getCharsetFromFile; this.addCharsetListener = addCharsetListener; @@ -226,7 +227,7 @@ Zotero.File = new function(){ // URL encode when saving attachments that trigger this fileName = fileName.replace(/[\/\\\?%\*:|"<>]/g, ''); // Replace newlines and tabs (which shouldn't be in the string in the first place) with spaces - fileName = fileName.replace(/[\n\t]/g, ' '); + fileName = fileName.replace(/[\r\n\t]+/g, ' '); // Replace various thin spaces fileName = fileName.replace(/[\u2000-\u200A]/g, ' '); // Replace zero-width spaces @@ -235,13 +236,44 @@ Zotero.File = new function(){ // Strip characters not valid in XML, since they won't sync and they're probably unwanted fileName = fileName.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\ud800-\udfff\ufffe\uffff]/g, ''); } - // Don't allow blank filename - if (!fileName) { + // Don't allow blank or illegal filenames + if (!fileName || fileName == '.' || fileName == '..') { fileName = '_'; } return fileName; } + /** + * Truncate a filename (excluding the extension) to the given total length + * If the "extension" is longer than 20 characters, + * it is treated as part of the file name + */ + function truncateFileName(fileName, maxLength) { + if(!fileName || (fileName + '').length <= maxLength) return fileName; + + var parts = (fileName + '').split(/\.(?=[^\.]+$)/); + var fn = parts[0]; + var ext = parts[1]; + //if the file starts with a period , use the whole file + //the whole file name might also just be a period + if(!fn) { + fn = '.' + (ext || ''); + } + + //treat long extensions as part of the file name + if(ext && ext.length > 20) { + fn += '.' + ext; + ext = undefined; + } + + if(ext === undefined) { //there was no period in the whole file name + ext = ''; + } else { + ext = '.' + ext; + } + + return fn.substr(0,maxLength-ext.length) + ext; + } /* * Not implemented, but it'd sure be great if it were From 1208aea99b10767d8ae58500e0360e260e09d29e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 20 Nov 2012 05:34:38 -0500 Subject: [PATCH 02/12] Fix double-click on attachments/notes when viewOnDoubleClick is false --- chrome/content/zotero/zoteroPane.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index fafbe920ad..6579441db1 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -2633,22 +2633,25 @@ var ZoteroPane = new function() } } else if (tree.id == 'zotero-items-tree') { - // Expand/collapse on triple-click - if (!Zotero.Prefs.get('viewOnDoubleClick')) { - return; + var viewOnDoubleClick = Zotero.Prefs.get('viewOnDoubleClick'); + if (viewOnDoubleClick) { + // Expand/collapse on triple-click, though the double-click + // will still trigger + if (event.detail == 3) { + tree.view.toggleOpenState(tree.view.selection.currentIndex); + return; + } + + // Don't expand/collapse on double-click + event.stopPropagation(); } - if (event.detail == 3) { - tree.view.toggleOpenState(tree.view.selection.currentIndex); - return; - } - - // Don't expand/collapse on double-click - event.stopPropagation(); - if (tree.view && tree.view.selection.currentIndex > -1) { var item = ZoteroPane_Local.getSelectedItems()[0]; if (item) { + if (!viewOnDoubleClick && item.isRegularItem()) { + return; + } ZoteroPane_Local.viewItems([item], event); } } From a56422be2c4b5f951f2eb9b8edd5e079ce8fd16a Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 21 Nov 2012 11:56:29 -0500 Subject: [PATCH 03/12] Fix for HTML markup showing up in reports (since 21bf3000) --- chrome/content/zotero/xpcom/report.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/report.js b/chrome/content/zotero/xpcom/report.js index fd4039ee46..38d4f090d3 100644 --- a/chrome/content/zotero/xpcom/report.js +++ b/chrome/content/zotero/xpcom/report.js @@ -80,7 +80,7 @@ Zotero.Report = new function() { // If not valid XML, display notes with entities encoded var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] .createInstance(Components.interfaces.nsIDOMParser); - var doc = parser.parseFromString(arr.note, "application/xml"); + var doc = parser.parseFromString('
' + arr.note + '
', "application/xml"); if (doc.documentElement.tagName == 'parsererror') { content += '

' + escapeXML(arr.note) + '

\n'; } @@ -106,7 +106,7 @@ Zotero.Report = new function() { // If not valid XML, display notes with entities encoded var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] .createInstance(Components.interfaces.nsIDOMParser); - var doc = parser.parseFromString(note.note, "application/xml"); + var doc = parser.parseFromString('
' + note.note + '
', "application/xml"); if (doc.documentElement.tagName == 'parsererror') { content += '

' + escapeXML(note.note) + '

\n'; } From 9665e67042a796a7bb396e25d18b9507257f4878 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 21 Nov 2012 19:42:47 -0500 Subject: [PATCH 04/12] Fix reports for notes with " " displaying as HTML markup Reports are now always served as text/html --- chrome/content/zotero/xpcom/report.js | 11 ++++++----- components/zotero-protocol-handler.js | 16 +--------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/chrome/content/zotero/xpcom/report.js b/chrome/content/zotero/xpcom/report.js index 38d4f090d3..f8df3a4c12 100644 --- a/chrome/content/zotero/xpcom/report.js +++ b/chrome/content/zotero/xpcom/report.js @@ -41,9 +41,8 @@ Zotero.Report = new function() { function generateHTMLDetails(items, combineChildItems) { - var content = '\n'; - content += '\n'; + var content = '\n'; + content += '\n'; content += '\n'; content += '' + Zotero.getString('report.title.default') + '\n'; content += '\n'; @@ -80,8 +79,9 @@ Zotero.Report = new function() { // If not valid XML, display notes with entities encoded var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] .createInstance(Components.interfaces.nsIDOMParser); - var doc = parser.parseFromString('
' + arr.note + '
', "application/xml"); + var doc = parser.parseFromString('
' + arr.note.replace(/ /g, " ") + '
', "application/xml"); if (doc.documentElement.tagName == 'parsererror') { + Zotero.debug(doc.documentElement.textContent, 2); content += '

' + escapeXML(arr.note) + '

\n'; } // Otherwise render markup normally @@ -106,8 +106,9 @@ Zotero.Report = new function() { // If not valid XML, display notes with entities encoded var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"] .createInstance(Components.interfaces.nsIDOMParser); - var doc = parser.parseFromString('
' + note.note + '
', "application/xml"); + var doc = parser.parseFromString('
' + note.note.replace(/ /g, " ") + '
', "application/xml"); if (doc.documentElement.tagName == 'parsererror') { + Zotero.debug(doc.documentElement.textContent, 2); content += '

' + escapeXML(note.note) + '

\n'; } // Otherwise render markup normally diff --git a/components/zotero-protocol-handler.js b/components/zotero-protocol-handler.js index c99d991955..a864e29d4d 100644 --- a/components/zotero-protocol-handler.js +++ b/components/zotero-protocol-handler.js @@ -479,21 +479,7 @@ function ChromeExtensionHandler() { default: var content = Zotero.Report.generateHTMLDetails(items, combineChildItems); - - // Serve invalid XML as text/html - // - // This is a temporary workaround until we figure out - // something better. - try { - var xml = new XML(content.replace(/^<\!DOCTYPE [^>]+>\n/, '').trim()); - mimeType = 'application/xhtml+xml'; - } - catch (e) { - Zotero.debug(e); - mimeType = 'text/html'; - } - - format = 'html'; + mimeType = 'text/html'; } } catch (e){ From 09e036e6faf9be0d535b0adb4fde1df446478f9d Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 22 Nov 2012 14:10:38 -0500 Subject: [PATCH 05/12] Fix XMLSerializer from translators --- chrome/content/zotero/xpcom/translation/translate_firefox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js index c6a2bd1929..ff4713e377 100644 --- a/chrome/content/zotero/xpcom/translation/translate_firefox.js +++ b/chrome/content/zotero/xpcom/translation/translate_firefox.js @@ -78,7 +78,7 @@ Zotero.Translate.SandboxManager = function(sandboxLocation) { }; }; this.sandbox.XMLSerializer.__exposedProps__ = {"prototype":"r"}; - this.sandbox.XMLSerializer.prototype = {}; + this.sandbox.XMLSerializer.prototype = {"__exposedProps__":{"serializeToString":"r"}}; } /** From 11d9c1df041821dabe7d97cef73bde90abe2e8c3 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 22 Nov 2012 16:35:18 -0500 Subject: [PATCH 06/12] Fix issue reported by Aurimas at http://forums.zotero.org/discussion/25058/?Focus=140039#Comment_140039 (broken by https://bugzilla.mozilla.org/show_bug.cgi?id=761620) --- chrome/content/zotero/xpcom/cookieSandbox.js | 24 ++++++++++++++++---- chrome/content/zotero/xpcom/http.js | 6 ++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/chrome/content/zotero/xpcom/cookieSandbox.js b/chrome/content/zotero/xpcom/cookieSandbox.js index e17a7423fe..20d0f7e89e 100755 --- a/chrome/content/zotero/xpcom/cookieSandbox.js +++ b/chrome/content/zotero/xpcom/cookieSandbox.js @@ -102,7 +102,8 @@ Zotero.CookieSandbox.prototype = { * @param {nsIInterfaceRequestor} ir */ "attachToInterfaceRequestor": function(ir) { - Zotero.CookieSandbox.Observer.trackedInterfaceRequestors.set(ir.QueryInterface(Components.interfaces.nsIInterfaceRequestor), this); + Zotero.CookieSandbox.Observer.trackedInterfaceRequestors.push(Components.utils.getWeakReference(ir.QueryInterface(Components.interfaces.nsIInterfaceRequestor))); + Zotero.CookieSandbox.Observer.trackedInterfaceRequestorSandboxes.push(this); } } @@ -125,7 +126,8 @@ Zotero.CookieSandbox.Observer = new function() { */ this.register = function(CookieSandbox) { this.trackedBrowsers = new WeakMap(); - this.trackedInterfaceRequestors = new WeakMap(); + this.trackedInterfaceRequestors = []; + this.trackedInterfaceRequestorSandboxes = []; if(!observing) { Zotero.debug("CookieSandbox: Registering observers"); @@ -145,8 +147,22 @@ Zotero.CookieSandbox.Observer = new function() { // try the notification callbacks if(notificationCallbacks) { - trackedBy = this.trackedInterfaceRequestors.get(notificationCallbacks); - if(trackedBy) { + for(var i=0; i Date: Thu, 22 Nov 2012 16:38:03 -0500 Subject: [PATCH 07/12] Log errors thrown by calls to Zotero.Attachments --- chrome/content/zotero/xpcom/translation/translate_item.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chrome/content/zotero/xpcom/translation/translate_item.js b/chrome/content/zotero/xpcom/translation/translate_item.js index 5828a751f1..fd9c8b4d87 100644 --- a/chrome/content/zotero/xpcom/translation/translate_item.js +++ b/chrome/content/zotero/xpcom/translation/translate_item.js @@ -233,6 +233,7 @@ Zotero.Translate.ItemSaver.prototype = { (attachment.title ? attachment.title : undefined)); } catch(e) { Zotero.debug("Translate: Error adding attachment "+attachment.url, 2); + Zotero.logError(e); return; } Zotero.debug("Translate: Created attachment; id is "+myID, 4); @@ -345,6 +346,7 @@ Zotero.Translate.ItemSaver.prototype = { (attachment.title ? attachment.title : undefined)); } catch(e) { Zotero.debug("Translate: Error adding attachment "+attachment.url, 2); + Zotero.logError(e); } } } else { @@ -354,6 +356,7 @@ Zotero.Translate.ItemSaver.prototype = { Zotero.Attachments.importFromDocument(attachment.document, parentID, attachment.title); } catch(e) { Zotero.debug("Translate: Error attaching document", 2); + Zotero.logError(e); } // Save attachment if snapshot pref enabled or not HTML // (in which case downloadAssociatedFiles applies) @@ -368,6 +371,7 @@ Zotero.Translate.ItemSaver.prototype = { fileBaseName, null, mimeType, this._libraryID, null, this._cookieSandbox); } catch(e) { Zotero.debug("Translate: Error adding attachment "+attachment.url, 2); + Zotero.logError(e); } } } From 36c5b57449b6a6fa8a6feed4a698e3e49ebe10d4 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 22 Nov 2012 16:40:23 -0500 Subject: [PATCH 08/12] Update versions --- chrome/content/zotero/xpcom/zotero.js | 2 +- install.rdf | 2 +- update.rdf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 11580841ea..90d4878856 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -35,7 +35,7 @@ const ZOTERO_CONFIG = { API_URL: 'https://api.zotero.org/', PREF_BRANCH: 'extensions.zotero.', BOOKMARKLET_URL: 'https://www.zotero.org/bookmarklet/', - VERSION: "3.0.10.SOURCE" + VERSION: "3.0.11.SOURCE" }; /* diff --git a/install.rdf b/install.rdf index e7a365a4e0..345fca70ee 100644 --- a/install.rdf +++ b/install.rdf @@ -6,7 +6,7 @@ zotero@chnm.gmu.edu Zotero - 3.0.10.SOURCE + 3.0.11.SOURCE Center for History and New Media
George Mason University
Dan Cohen Sean Takats diff --git a/update.rdf b/update.rdf index 4001ecc250..05bd2f47f6 100644 --- a/update.rdf +++ b/update.rdf @@ -7,7 +7,7 @@ - 3.0.10.SOURCE + 3.0.11.SOURCE {ec8030f7-c20a-464f-9b0e-13a3a9e97384} From 520309bfa409297ff3958e1aac761eaff8da4f47 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 22 Nov 2012 16:58:45 -0500 Subject: [PATCH 09/12] Fix typo --- chrome/content/zotero/xpcom/cookieSandbox.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/cookieSandbox.js b/chrome/content/zotero/xpcom/cookieSandbox.js index 20d0f7e89e..0d013ad91f 100755 --- a/chrome/content/zotero/xpcom/cookieSandbox.js +++ b/chrome/content/zotero/xpcom/cookieSandbox.js @@ -162,7 +162,7 @@ Zotero.CookieSandbox.Observer = new function() { } } - if(!trackedBy) { + if(trackedBy) { tested = true; } else { // try the browser From a57dd18afa22c3c5087f2d54d41dc56556e86a35 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 22 Nov 2012 16:58:51 -0500 Subject: [PATCH 10/12] Use cookieSandbox when saving snapshots --- chrome/content/zotero/xpcom/attachments.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index 753c79c0ed..ecb3b31393 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -232,7 +232,7 @@ Zotero.Attachments = new function(){ }; Zotero.Attachments.importFromDocument(browser.contentDocument, sourceItemID, forceTitle, parentCollectionIDs, importCallback, libraryID); - }, undefined, undefined, true); + }, undefined, undefined, true, cookieSandbox); }; // Save using remote web browser persist From 939719866ff0bbbb2824b9eee1d6edb6b419a6ae Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 22 Nov 2012 22:51:10 -0500 Subject: [PATCH 11/12] Fixes #199, Don't lowercase snapshot filenames @aurimasv, let me know if this looks OK to you --- chrome/content/zotero/webpagedump/common.js | 2 +- chrome/content/zotero/webpagedump/domsaver.js | 15 ++++++++------- chrome/content/zotero/xpcom/attachments.js | 5 +++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/webpagedump/common.js b/chrome/content/zotero/webpagedump/common.js index 673be0d9e3..2e290d06b4 100644 --- a/chrome/content/zotero/webpagedump/common.js +++ b/chrome/content/zotero/webpagedump/common.js @@ -357,7 +357,7 @@ var wpdCommon = { // replace illegal characters // and shorten long file names getValidFileName: function (aFileName) { - aFileName = Zotero.File.getValidFileName(aFileName).toLowerCase(); + aFileName = Zotero.File.getValidFileName(aFileName); return Zotero.File.truncateFileName(aFileName, WPD_MAX_FILENAME_LENGTH); }, diff --git a/chrome/content/zotero/webpagedump/domsaver.js b/chrome/content/zotero/webpagedump/domsaver.js index 725b6e249e..d7b38d6ea1 100644 --- a/chrome/content/zotero/webpagedump/domsaver.js +++ b/chrome/content/zotero/webpagedump/domsaver.js @@ -675,7 +675,7 @@ var wpdDOMSaver = { //returns a unique file name and registers it getUniqueFileNameAndRegister: function(fileName, sourceURL, content) { fileName = this.checkForEqualFilenames( - wpdCommon.getValidFileName(fileName).toLowerCase(), + wpdCommon.getValidFileName(fileName), sourceURL); this.registerFile(fileName, sourceURL, content); return fileName; @@ -683,7 +683,7 @@ var wpdDOMSaver = { //register filename, so we don't overwrite them later registerFile: function (newFileName, sourceURL, content) { - this.fileInfo[newFileName] = { + this.fileInfo[newFileName.toLowerCase()] = { url: sourceURL, downloaded: content } @@ -691,11 +691,12 @@ var wpdDOMSaver = { // is the file registered (e.g. downloaded)? isFileRegistered: function (newFileName) { - if (this.fileInfo[newFileName] != undefined) return true; + if (this.fileInfo[newFileName.toLowerCase()] != undefined) return true; return false; }, isDownloaded: function(fileName) { + fileName = fileName.toLowerCase(); if(!this.fileInfo[fileName]) return; return this.fileInfo[fileName].downloaded; }, @@ -705,16 +706,16 @@ var wpdDOMSaver = { // if no aURLSpec is passed, this generates a unique file name checkForEqualFilenames: function (newFileName, aURLSpec) { if (this.isFileRegistered(newFileName)) { - if (!aURLSpec || this.fileInfo[newFileName]["url"] != aURLSpec) { + if (!aURLSpec || this.fileInfo[newFileName.toLowerCase()]["url"] != aURLSpec) { // the file is already registered but from a different location // => probably not the same file, so we have to find a different name it (e.g. filename_001.ext) var seq = 1; var fileLR = wpdCommon.splitFileName(newFileName); if (!fileLR[1]) fileLR[1] = "dat"; newFileName = fileLR[0] + "_" + wpdCommon.addLeftZeros(seq++, 3) + "." + fileLR[1]; - while (this.fileInfo[newFileName] != undefined) { + while (this.fileInfo[newFileName.toLowerCase()] != undefined) { // is the file already registered with the new name? - if (aURLSpec && this.fileInfo[newFileName]["url"] == aURLSpec) return newFileName; // Yes -> so it�s already downloaded and we are finished + if (aURLSpec && this.fileInfo[newFileName.toLowerCase()]["url"] == aURLSpec) return newFileName; // Yes -> so it's already downloaded and we are finished newFileName = fileLR[0] + "_" + wpdCommon.addLeftZeros(seq++, 3) + "." + fileLR[1]; // No -> "increment" filename } } @@ -734,7 +735,7 @@ var wpdDOMSaver = { var aURL = wpdCommon.convertURLToObject(aURLSpec); // generate a filename - var newFileName = aURL.fileName.toLowerCase(); + var newFileName = aURL.fileName; if (!newFileName) newFileName = "untitled"; // same name but different location? newFileName = this.getUniqueFileNameAndRegister(newFileName, aURLSpec); diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index ecb3b31393..f9acbf5e8e 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -547,8 +547,9 @@ Zotero.Attachments = new function(){ file.initWithFile(destDir); var fileName = Zotero.File.truncateFileName( - _getFileNameFromURL(url, mimeType).toLowerCase(), - 100); //make sure this matches WPD settings in webpagedump/common.js + _getFileNameFromURL(url, mimeType), + 100 //make sure this matches WPD settings in webpagedump/common.js + ); file.append(fileName) if (mimeType == 'application/pdf') { From 3403bedc8eb063f246b1162625221c7e8225b39f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 22 Nov 2012 23:28:25 -0500 Subject: [PATCH 12/12] Update translators and repotime --- repotime.txt | 2 +- translators | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/repotime.txt b/repotime.txt index cbe0afbf98..606f4a2b5b 100644 --- a/repotime.txt +++ b/repotime.txt @@ -1 +1 @@ -2012-11-18 22:15:00 +2012-11-22 19:15:00 diff --git a/translators b/translators index dfd0239e0e..2c33d5d461 160000 --- a/translators +++ b/translators @@ -1 +1 @@ -Subproject commit dfd0239e0e042d5ba4da0e806003849f6e1b1e7a +Subproject commit 2c33d5d461cab0749702529e26686738e7a0b411