From 51f6e1650d6436d9aae5e14448474c7f793aca06 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Mon, 1 Jun 2009 20:13:09 +0000 Subject: [PATCH] Better (and centralized) DOI parsing --- chrome/content/zotero/bindings/itembox.xml | 4 ++-- chrome/content/zotero/overlay.js | 2 +- chrome/content/zotero/xpcom/utilities.js | 10 ++++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/chrome/content/zotero/bindings/itembox.xml b/chrome/content/zotero/bindings/itembox.xml index 0862e755fa..104b3901e8 100644 --- a/chrome/content/zotero/bindings/itembox.xml +++ b/chrome/content/zotero/bindings/itembox.xml @@ -265,7 +265,7 @@ var doi = this.item.getField('DOI'); if (doi) { // Pull out DOI, in case there's a prefix - doi = doi.match(/10\..*/); + doi = Zotero.Utilities.prototype.cleanDOI(doi);; if (doi) { spec = "http://dx.doi.org/" + encodeURIComponent(doi); } @@ -454,7 +454,7 @@ } else if (fieldName == 'DOI' && val) { // Pull out DOI, in case there's a prefix - var doi = val.match(/10\..*/); + var doi = Zotero.Utilities.prototype.cleanDOI(val); if (doi) { doi = "http://dx.doi.org/" + encodeURIComponent(doi); label.setAttribute("isButton", true); diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 2a1cae6d7e..6f557dff90 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -1962,7 +1962,7 @@ var ZoteroPane = new function() var doi = item.getField('DOI'); if (doi) { // Pull out DOI, in case there's a prefix - doi = doi.match(/10\..*/); + doi = Zotero.Utilities.prototype.cleanDOI(doi); if (doi) { uri = "http://dx.doi.org/" + encodeURIComponent(doi); } diff --git a/chrome/content/zotero/xpcom/utilities.js b/chrome/content/zotero/xpcom/utilities.js index 1d5b7cd6e6..3a55a4daae 100644 --- a/chrome/content/zotero/xpcom/utilities.js +++ b/chrome/content/zotero/xpcom/utilities.js @@ -143,6 +143,16 @@ Zotero.Utilities.prototype.cleanTags = function(/**String*/ x) { return x.replace(/<[^>]+>/g, ""); } + +Zotero.Utilities.prototype.cleanDOI = function(/**String**/ x) { + if(typeof(x) != "string") { + throw "cleanDOI: argument must be a string"; + } + + return x.match(/10\.[^\s\/]+\/[^\s]+/); +} + + /** * Encode special XML/HTML characters
*