Skip to content

Commit

Permalink
Merge branch 'next' into refactor/changelog-include-locale-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ST-DDT authored Jan 20, 2023
2 parents a67a404 + 2e6b136 commit 27216e1
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/locales/el/person/last_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default [
'Αρβανίτης',
'Αργυριάδης',
'Ασπάσιος',
'Αυγερινός (επώνυμο)',
'Αυγερινός',
'Βάμβας',
'Βαμβακάς',
'Βαρνακιώτης',
Expand Down Expand Up @@ -147,7 +147,7 @@ export default [
'Λόντος',
'Λύτρας',
'Λαγός',
'Λαιμός (επώνυμο)',
'Λαιμός',
'Λαμέρας',
'Λαμπρόπουλος',
'Λειβαδάς',
Expand Down
2 changes: 1 addition & 1 deletion src/locales/fa/person/last_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default [
'کوشکی',
'کهنمویی',
'کیان',
'کیانی (نام خانوادگی)',
'کیانی',
'کیمیایی',
'گل محمدی',
'گلپایگانی',
Expand Down
14 changes: 14 additions & 0 deletions src/locales/hu/company/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* This file is automatically generated.
* Run 'pnpm run generate:locales' to update.
*/
import type { CompanyDefinitions } from '../../..';
import name_patterns from './name_patterns';
import suffix from './suffix';

const company: CompanyDefinitions = {
name_patterns,
suffix,
};

export default company;
6 changes: 6 additions & 0 deletions src/locales/hu/company/name_patterns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default [
'{{person.last_name}} {{company.suffix}}',
'{{person.last_name}} és {{person.last_name}} {{company.suffix}}',
'{{person.last_name}} és Tsa. {{company.suffix}}',
'{{person.last_name}} 2000 {{company.suffix}}',
];
1 change: 1 addition & 0 deletions src/locales/hu/company/suffix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ['Kft.', 'Bt.', 'Zrt.', 'Nyrt.', 'Kv.', 'Kkt.'];
2 changes: 2 additions & 0 deletions src/locales/hu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import type { LocaleDefinition } from '../..';
import animal from './animal';
import commerce from './commerce';
import company from './company';
import date from './date';
import finance from './finance';
import internet from './internet';
Expand All @@ -16,6 +17,7 @@ const hu: LocaleDefinition = {
title: 'Hungarian',
animal,
commerce,
company,
date,
finance,
internet,
Expand Down
7 changes: 7 additions & 0 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ export class InternetModule {
);

let localPart: string = this.userName(firstName, lastName);
// Strip any special characters from the local part of the email address
// This could happen if invalid chars are passed in manually in the firstName/lastName
localPart = localPart.replace(/[^A-Za-z0-9._+\-]+/g, '');

// The local part of an email address is limited to 64 chars per RFC 3696
// We limit to 50 chars to be more realistic
localPart = localPart.substring(0, 50);
if (options?.allowSpecialCharacters) {
const usernameChars: string[] = '._-'.split('');
const specialChars: string[] = ".!#$%&'*+-/=?^_`{|}~".split('');
Expand Down
19 changes: 19 additions & 0 deletions test/internet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,25 @@ describe('internet', () => {
expect(faker.definitions.internet.free_email).toContain(suffix);
});

it('should return a valid email for very long names', () => {
const longFirstName =
'Elizabeth Alexandra Mary Jane Annabel Victoria';
const longSurname = 'Smith Jones Davidson Brown White Greene Black';
const email = faker.internet.email(longFirstName, longSurname);
// should truncate to 50 chars
// e.g. ElizabethAlexandraMaryJaneAnnabelVictoria.SmithJon@yahoo.com
expect(email).toSatisfy(validator.isEmail);
const localPart = email.split('@')[0];
expect(localPart.length).toBeLessThanOrEqual(50);
});

it('should return a valid email for names with invalid chars', () => {
const email = faker.internet.email('Matthew (Matt)', 'Smith');
// should strip invalid chars
// e.g. MatthewMatt_Smith@yahoo.com
expect(email).toSatisfy(validator.isEmail);
});

it('should return an email with special characters', () => {
const email = faker.internet.email('Mike', 'Smith', null, {
allowSpecialCharacters: true,
Expand Down

0 comments on commit 27216e1

Please sign in to comment.