Skip to content

Commit

Permalink
catch name parsing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrayson676 committed Oct 15, 2024
1 parent eec4292 commit 9650444
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 7 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ module.exports = {

// given a string containing a person's full name, return a two-element array containing firstName and lastName
parseFullname(fullname) {
const parsed = humanname.parse(fullname);
let parsed;

try {
parsed = humanname.parse(fullname);
} catch (e) {
parsed = { firstName: fullname };
}

return {
salutation: parsed.salutation,
Expand Down
5 changes: 0 additions & 5 deletions test/http-error-spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
const { assert } = require('chai');
const HttpError = require('../lib/http-error');

Expand Down
10 changes: 5 additions & 5 deletions test/util-spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/
const { assert } = require('chai');
const utils = require('../lib/util');

Expand Down Expand Up @@ -36,6 +31,11 @@ describe('Utility functions', function() {
assert.equal(parsed.last_name, "Wooten");
assert.equal(parsed.suffix, "III");
});

it('should handle parser errors by defaulting to only setting first name', function () {
const parsed = utils.parseFullname('Foo(Bar)');
assert.equal(parsed.first_name, 'Foo(Bar)');
});
});

describe('validateRequest', function() {
Expand Down

0 comments on commit 9650444

Please sign in to comment.