Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(internet): userName, email and slugify return only ascii #1554

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
405b129
fix(internet): use a ascii-only fallback for email addresses in some …
matthewmayer Nov 13, 2022
4b137b4
fix(internet): use a ascii-only fallback for email addresses in some …
matthewmayer Nov 13, 2022
bf18f4a
fix(internet): use a ascii-only fallback for email addresses in some …
matthewmayer Nov 13, 2022
ddbb19a
fix(internet): use a ascii-only fallback for email addresses in some …
matthewmayer Nov 13, 2022
219173d
Update src/modules/internet/index.ts
Nov 17, 2022
8560c5d
Merge branch 'next' into chore/fallback-ascii-email-addresses
Nov 17, 2022
c37ffcd
fix(internet): use a ascii-only fallback for email addresses in some …
matthewmayer Nov 20, 2022
d4b958b
fix(internet): make faker.internet.userName return ASCII only
matthewmayer Nov 25, 2022
83cd519
fix(internet): make faker.internet.userName return ASCII only - and u…
matthewmayer Nov 25, 2022
225de8d
fix(internet): add faker.internet.displayName
matthewmayer Nov 25, 2022
5280dd0
fix(internet): add displayName tests, add Greek
matthewmayer Nov 25, 2022
95fb1d8
Merge branch 'next' into chore/fallback-ascii-email-addresses
Nov 25, 2022
f16a53c
fix(internet): fix deprecations
matthewmayer Nov 25, 2022
82cb254
fix(internet): fix lint
matthewmayer Nov 25, 2022
9e66225
fix(internet): new source and add arabic,farsi,armenian
matthewmayer Nov 25, 2022
b717385
Update src/modules/internet/index.ts
Nov 27, 2022
4b0ee08
Update src/modules/internet/index.ts
Nov 27, 2022
2e1b5f6
Update test/internet.spec.ts
Nov 27, 2022
5b2757a
fix(internet): improve tests and docs
matthewmayer Nov 27, 2022
4884f27
fix(internet): improve tests and docs
matthewmayer Nov 27, 2022
bc636c5
Merge branch 'next' into chore/fallback-ascii-email-addresses
ST-DDT Nov 27, 2022
3505045
Update src/modules/internet/char-mappings.ts
Nov 29, 2022
8657c47
Merge branch 'next' into chore/fallback-ascii-email-addresses
ST-DDT Nov 30, 2022
c9caafc
fix: comment fixes
matthewmayer Dec 1, 2022
cdb5d4f
Merge branch 'next' into chore/fallback-ascii-email-addresses
ST-DDT Dec 1, 2022
d461e30
Merge branch 'next' into chore/fallback-ascii-email-addresses
ST-DDT Dec 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/modules/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export class HelpersModule {
* @since 2.0.1
*/
slugify(string: string = ''): string {
return string
.replace(/ /g, '-')
.replace(/[^\一-龠\ぁ-ゔ\ァ-ヴー\w\.\-]+/g, '');
return string.replace(/ /g, '-').replace(/[^\w\.\-]+/g, '');
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/modules/internet/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export class InternetModule {
this.userName(firstName, lastName)
);

//In some locales e.g. ja or el, userName contains mostly non-Unicode characters
//https://github.com/faker-js/faker/issues/1105
//After slugify it becomes a string with only 0-9, _ and .
//In that case we generate a purely random local part instead
matthewmayer marked this conversation as resolved.
Show resolved Hide resolved
const invalidLocalPart: boolean = /^[0-9\._]*$/.test(localPart);
if (invalidLocalPart) {
localPart =
this.faker.string.alpha({ length: 2, casing: 'lower' }) +
this.faker.datatype.number({ min: 10000, max: 9999999 }).toString();
}
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved
if (options?.allowSpecialCharacters) {
const usernameChars: string[] = '._-'.split('');
const specialChars: string[] = ".!#$%&'*+-/=?^_`{|}~".split('');
Expand Down
27 changes: 0 additions & 27 deletions test/internet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,6 @@ describe('internet', () => {
expect(faker.definitions.internet.free_email).toContain(suffix);
});

it('should return an email with japanese characters', () => {
Shinigami92 marked this conversation as resolved.
Show resolved Hide resolved
const email = faker.internet.email('思源_唐3');

expect(email).toBeTruthy();
expect(email).toBeTypeOf('string');
expect(email).toSatisfy(validator.isEmail);

const [prefix, suffix] = email.split('@');

expect(prefix).toMatch(/^思源_唐3/);
expect(faker.definitions.internet.free_email).toContain(suffix);
});

it('should return an email with special characters', () => {
const email = faker.internet.email('Mike', 'Smith', null, {
allowSpecialCharacters: true,
Expand Down Expand Up @@ -203,20 +190,6 @@ describe('internet', () => {
expect(prefix).toMatch(/^Aiden([._]Harann)?\d*/);
});

it('should return an email with the example suffix and japanese characters', () => {
const email = faker.internet.exampleEmail('思源_唐3');

expect(email).toBeTruthy();
expect(email).toBeTypeOf('string');
expect(email).toSatisfy(validator.isEmail);

const [prefix, suffix] = email.split('@');

expect(suffix).toMatch(/^example\.(com|net|org)$/);
expect(faker.definitions.internet.example_email).toContain(suffix);
expect(prefix).toMatch(/^思源_唐3/);
});

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