From f7777ae108198832ab707bdd9e00442f2dc8a9ec Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 23 Jan 2008 08:29:11 +0000 Subject: [PATCH] Attachment filenames based on item data didn't include other characters in the format string (such as spaces and hyphens) --- chrome/content/zotero/xpcom/attachments.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index f58983883..8335e4355 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -828,21 +828,21 @@ Zotero.Attachments = new function(){ var value = item.getField(field, false, true); } + var re = new RegExp("\{?([^%\{\}]*)" + rpl + "(\{[0-9]+\})?" + "([^%\{\}]*)\}?"); + // If no value for this field, strip entire conditional block // (within curly braces) if (!value) { - var re = new RegExp("\{[^%]*" + rpl + "(\{[0-9]+\})?" + "[^%]*\}"); if (str.match(re)) { return str.replace(re, '') } } - var f = function(match) { - var chars = match.match(/{([0-9]+)}/); - return (chars) ? value.substr(0, chars[1]) : value; + var f = function(match, p1, p2, p3) { + var maxChars = p2 ? p2.replace(/[^0-9]+/g, '') : false; + return p1 + (maxChars ? value.substr(0, maxChars) : value) + p3; } - var re = new RegExp("(\{[^%]*)?" + rpl + "(\{[0-9]+\})?" + "([^%]*\})?"); return str.replace(re, f); }