Skip to content

Commit

Permalink
Merge pull request zotero#1172 from adomasven/fix/clean-authors
Browse files Browse the repository at this point in the history
Get a better last name if current guess starts with weird symbols
  • Loading branch information
dstillman committed Feb 18, 2017
2 parents e8ac639 + bf1c52a commit 07ea9da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
10 changes: 7 additions & 3 deletions chrome/content/zotero/xpcom/utilities.js
Expand Up @@ -179,9 +179,13 @@ Zotero.Utilities = {
var lastName = author;
}
} else {
var spaceIndex = author.lastIndexOf(" ");
var lastName = author.substring(spaceIndex+1);
var firstName = author.substring(0, spaceIndex);
// Don't parse "Firstname Lastname [Country]" as "[Country], Firstname Lastname"
var spaceIndex = author.length;
do {
spaceIndex = author.lastIndexOf(" ", spaceIndex-1);
var lastName = author.substring(spaceIndex + 1);
var firstName = author.substring(0, spaceIndex);
} while (!Zotero.Utilities.XRegExp('\\pL').test(lastName[0]) && spaceIndex > 0)
}

if(firstName && allCapsRe.test(firstName) &&
Expand Down
15 changes: 15 additions & 0 deletions test/tests/utilitiesTest.js
Expand Up @@ -16,6 +16,21 @@ describe("Zotero.Utilities", function() {
}
}
});

it('should not parse words starting with symbols as last name', function() {
let author = Zotero.Utilities.cleanAuthor('First Middle Last [CountryName]', false);
assert.equal(author.firstName, 'First Middle');
// Brackets at the beginning and end of a string get removed for strings
// such as [First Last] -> Last, First.
// The current output is not ideal, but better than "[CountryName, First Middle Last"
assert.equal(author.lastName, 'Last [CountryName');
});

it('should parse names starting with unicode characters correctly', function() {
let author = Zotero.Utilities.cleanAuthor('Ąžuolas Žolynas', false);
assert.equal(author.firstName, 'Ąžuolas');
assert.equal(author.lastName, 'Žolynas');
})
});
describe("cleanISBN", function() {
let cleanISBN = Zotero.Utilities.cleanISBN;
Expand Down

0 comments on commit 07ea9da

Please sign in to comment.