Fix Quick Copy in tab mode, but for real

This commit is contained in:
Dan Stillman 2015-07-03 22:06:12 -04:00
parent 20f279043b
commit 242581a270
2 changed files with 38 additions and 4 deletions

View File

@ -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];

View File

@ -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);
})
})
})