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

Unreachable code in finance.creditCardNumber() #375

Closed
ST-DDT opened this issue Jan 30, 2022 · 1 comment · Fixed by #508
Closed

Unreachable code in finance.creditCardNumber() #375

ST-DDT opened this issue Jan 30, 2022 · 1 comment · Fixed by #508
Assignees
Labels
c: bug Something isn't working p: 1-normal Nothing urgent

Comments

@ST-DDT
Copy link
Member

ST-DDT commented Jan 30, 2022

Describe the bug

faker/src/finance.ts

Lines 231 to 261 in d4125e2

creditCardNumber(provider = ''): string {
let format: string;
let formats: string | string[];
const localeFormat = this.faker.definitions.finance.credit_card;
if (provider in localeFormat) {
formats = localeFormat[provider]; // there could be multiple formats
if (typeof formats === 'string') {
format = formats;
} else {
format = this.faker.random.arrayElement(formats);
}
} else if (provider.match(/#/)) {
// The user chose an optional scheme
format = provider;
} else {
// Choose a random provider
if (typeof localeFormat === 'string') {
format = localeFormat;
} else if (typeof localeFormat === 'object') {
// Credit cards are in a object structure
formats = this.faker.random.objectElement(localeFormat, 'value'); // There could be multiple formats
if (typeof formats === 'string') {
format = formats;
} else {
format = this.faker.random.arrayElement(formats);
}
}
}
format = format.replace(/\//g, '');
return this.Helpers.replaceCreditCardSymbols(format);
}

Due to

if (provider in localeFormat) {

localeFormat cannot be a string thus

faker/src/finance.ts

Lines 247 to 248 in d4125e2

if (typeof localeFormat === 'string') {
format = localeFormat;

is unreachable

Reproduction

Set the faker.definitions.finance.credit_card to a string and run the method.

Additional Info

Discovered in #363

@ST-DDT ST-DDT added the c: bug Something isn't working label Jan 30, 2022
@Shinigami92 Shinigami92 added this to the v6.1 - First bugfixes milestone Jan 30, 2022
@Shinigami92 Shinigami92 moved this to Todo in Faker Roadmap Jan 30, 2022
@ejcheng ejcheng added the p: 1-normal Nothing urgent label Jan 30, 2022
@xDivisionByZerox
Copy link
Member

I would provide a PR for this, Can someone assign me to this?

@ST-DDT ST-DDT linked a pull request Feb 19, 2022 that will close this issue
Repository owner moved this from Todo to Done in Faker Roadmap Mar 21, 2022
@ST-DDT ST-DDT removed this from Faker Roadmap Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working p: 1-normal Nothing urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants