Mvolz has uploaded a new change for review. https://gerrit.wikimedia.org/r/234262
Change subject: Replace nbsp in author strings with spaces ...................................................................... Replace nbsp in author strings with spaces Some author strings contained nbsp instead of spaces, which caused duplicate authors to be added in some cases. T109431 Change-Id: I3f87b52f021359f6c0a8941a964eca848046bd65 --- M lib/translators/coins.js M test/features/scraping/index.js M test/features/unit/coins.js 3 files changed, 24 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/citoid refs/changes/62/234262/1 diff --git a/lib/translators/coins.js b/lib/translators/coins.js index d0167be..ba6b2e8 100644 --- a/lib/translators/coins.js +++ b/lib/translators/coins.js @@ -69,13 +69,14 @@ firstAuthor = {creatorType: 'author'}; firstAuthor.lastName = metadata.aulast || ''; + firstAuthor.lastName = firstAuthor.lastName.replace(String.fromCharCode(160), ' '); // Replace any nbsp with space if (metadata.ausuffix){ firstAuthor.lastName += ', ' + metadata.ausuffix; } if (metadata.aufirst !== undefined){ - firstAuthor.firstName = metadata.aufirst; + firstAuthor.firstName = metadata.aufirst.replace(String.fromCharCode(160), ' '); // Replace any nbsp with space } else if (metadata.auinit !== undefined) { firstAuthor.firstName = metadata.auinit; } else if (metadata.auinit1 !== undefined) { @@ -94,13 +95,14 @@ creators.push(firstAuthor); } + // Add remaining authors in au field function addAu(){ if (!metadata.au || !Array.isArray(metadata.au)){ return; } for (i = 0; i < metadata.au.length; i++) { creatorObj = {creatorType: 'author'}; - authorText = metadata.au[i]; + authorText = metadata.au[i].replace(String.fromCharCode(160), ' '); // Replace any nbsp with space if (!authorText){ return; } diff --git a/test/features/scraping/index.js b/test/features/scraping/index.js index 0c8aab6..288b8e5 100644 --- a/test/features/scraping/index.js +++ b/test/features/scraping/index.js @@ -308,6 +308,7 @@ assert.status(res, 200); assert.checkCitation(res, 'Salaries, Turnover, and Performance in the Federal Criminal Justice System*'); assert.deepEqual(res.body[0].DOI, '10.1086/378695'); + assert.deepEqual(res.body[0].author.length, 1); }); }); diff --git a/test/features/unit/coins.js b/test/features/unit/coins.js index 2b08ee9..8f1376c 100644 --- a/test/features/unit/coins.js +++ b/test/features/unit/coins.js @@ -76,6 +76,25 @@ assert.deepEqual(result, expected); }); + it('Doesn\'t add duplicate author names with nbsp present', function() { + expected = { + creators: [{ + creatorType: 'author', + firstName: 'Firstname', + lastName: 'Lastname, Jr.' + }] + }; + input = { + aulast: 'Lastname', + aufirst: 'Firstname', + ausuffix: 'Jr.', + au: ['Firstname Lastname, Jr.'] // String containing nbsp instead of traditional space + }; + input.au[0] = input.au[0].replace(' ', String.fromCharCode(160)); // Make au string containing nbsp instead of traditional space + result = coins.general.addAuthors({}, input); + assert.deepEqual(result, expected); + }); + it('Correctly adds name with missing firstname', function() { expected = { creators: [{ -- To view, visit https://gerrit.wikimedia.org/r/234262 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3f87b52f021359f6c0a8941a964eca848046bd65 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/services/citoid Gerrit-Branch: master Gerrit-Owner: Mvolz <mv...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits