From 4ad2a4f5bf14501e69655d1d96b623e4fe059e8f Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 16 Jun 2009 06:52:17 +0000 Subject: [PATCH] Fix broken documents after syncing for the first time with 2.0b5 --- chrome/content/zotero/xpcom/uri.js | 33 +++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/uri.js b/chrome/content/zotero/xpcom/uri.js index cc03e94c8..d1c842ad2 100644 --- a/chrome/content/zotero/xpcom/uri.js +++ b/chrome/content/zotero/xpcom/uri.js @@ -2,6 +2,26 @@ Zotero.URI = new function () { var _baseURI = ZOTERO_CONFIG.BASE_URI; + /** + * Get a URI with the user's local key, if there is one + * + * @return {String|False} e.g., 'http://zotero.org/users/v3aG8nQf' + */ + this.getLocalUserURI = function () { + var key = Zotero.getLocalUserKey(); + if (!key) { + return false; + } + + return _baseURI + "users/local/" + Zotero.getLocalUserKey(); + } + + + /** + * Get a URI for the user, creating a local user key if necessary + * + * @return {String} + */ this.getCurrentUserURI = function () { var userID = Zotero.userID; if (userID) { @@ -78,11 +98,14 @@ Zotero.URI = new function () { // If this is a local URI, compare to the local user key if (itemURI.match(/\/users\/local\//)) { - var currentUserURI = this.getCurrentUserURI() + "/"; - if (itemURI.indexOf(currentUserURI) == 0) { - itemURI = itemURI.substr(currentUserURI.length); - var libraryType = 'user'; - var libraryTypeID = null; + var localUserURI = this.getLocalUserURI(); + if (localUserURI) { + localUserURI += "/"; + if (itemURI.indexOf(localUserURI) == 0) { + itemURI = itemURI.substr(localUserURI.length); + var libraryType = 'user'; + var libraryTypeID = null; + } } }