Hyphenate ISBN when writing to DB

Only hyphenate if we're very confident that it's a list of unhyphenated ISBNs
This commit is contained in:
Aurimas Vinckevicius 2015-02-19 04:36:52 -06:00
parent 68e7849fcf
commit 3918adf21a

View File

@ -821,6 +821,24 @@ Zotero.Item.prototype.setField = function(field, value, loadIn) {
value = value.replace(/[\r\n]+/g, " ");;
}
if (fieldID == Zotero.ItemFields.getID('ISBN')) {
// Hyphenate ISBNs, but only if everything is in expected format and valid
let isbns = ('' + value).trim().split(/\s*[,;]\s*|\s+/),
newISBNs = '',
failed = false;
for (let i=0; i<isbns.length; i++) {
let isbn = Zotero.Utilities.Internal.hyphenateISBN(isbns[i]);
if (!isbn) {
failed = true;
break;
}
newISBNs += ' ' + isbn;
}
if (!failed) value = newISBNs.substr(1);
}
if (!loadIn) {
// Save date field as multipart date
// TEMP - filingDate