commit 242581a270daf602697dac7b74d8eced35a408b6
parent 20f279043bdfc103ddd1de13c455c15d3e07c538
Author: Dan Stillman <dstillman@zotero.org>
Date: Fri, 3 Jul 2015 22:06:12 -0400
Fix Quick Copy in tab mode, but for real
Diffstat:
2 files changed, 38 insertions(+), 4 deletions(-)
diff --git a/chrome/content/zotero/xpcom/quickCopy.js b/chrome/content/zotero/xpcom/quickCopy.js
@@ -104,8 +104,9 @@ Zotero.QuickCopy = new function() {
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
+ var nsIURI;
try {
- var nsIURI = ioService.newURI(url, null, null);
+ nsIURI = ioService.newURI(url, null, null);
// Accessing some properties may throw for URIs that do not support those
// parts. E.g. hostPort throws NS_ERROR_FAILURE for about:blank
var urlHostPort = nsIURI.hostPort;
@@ -113,8 +114,8 @@ Zotero.QuickCopy = new function() {
}
catch (e) {}
- // Skip about:, chrome:, etc.
- if (!urlHostPort) {
+ // Skip non-HTTP URLs
+ if (!/^https?$/.test(nsIURI.scheme)) {
return quickCopyPref;
}
@@ -122,7 +123,12 @@ Zotero.QuickCopy = new function() {
var sql = "SELECT key AS domainPath, value AS format FROM settings "
+ "WHERE setting='quickCopySite' AND (key LIKE ? OR key LIKE ?)";
- var urlDomain = urlHostPort.match(/[^\.]+\.[^\.]+$/);
+ var urlDomain = urlHostPort.match(/(?:[^\.]+\.)?[^\.]+$/);
+ // Hopefully can't happen, but until we're sure
+ if (!urlDomain) {
+ Zotero.logError("Quick Copy host '" + urlHostPort + "' not matched");
+ return quickCopyPref;
+ }
var rows = Zotero.DB.query(sql, ['%' + urlDomain[0] + '%', '/%']);
for (let i = 0; i < rows.length; i++) {
let row = rows[i];
diff --git a/test/tests/quickCopyTest.js b/test/tests/quickCopyTest.js
@@ -0,0 +1,28 @@
+describe("Zotero.QuickCopy", function() {
+ var quickCopyPref = Zotero.Prefs.get("export.quickCopy.setting");
+ quickCopyPref = JSON.stringify(Zotero.QuickCopy.unserializeSetting(quickCopyPref));
+
+ // TODO: These should set site-specific prefs and test the actual response against it,
+ // but that will need to wait for 5.0. For now, just make sure they don't fail.
+ describe("#getFormatFromURL()", function () {
+ it("should handle a domain", function () {
+ assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo.com/'), quickCopyPref);
+ })
+
+ it("should handle a domain and path", function () {
+ assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo.com/bar'), quickCopyPref);
+ })
+
+ it("should handle a local host", function () {
+ assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('http://foo/'), quickCopyPref);
+ })
+
+ it("should handle an about: URL", function () {
+ assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('about:blank'), quickCopyPref);
+ })
+
+ it("should handle a chrome URL", function () {
+ assert.deepEqual(Zotero.QuickCopy.getFormatFromURL('chrome://zotero/content/tab.xul'), quickCopyPref);
+ })
+ })
+})