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: prevent infinite loop with locale #2179

Merged
merged 2 commits into from May 15, 2022
Merged

fix: prevent infinite loop with locale #2179

merged 2 commits into from May 15, 2022

Conversation

jly36963
Copy link
Contributor

@jly36963 jly36963 commented May 6, 2022

Addresses: #2178

Description

locale and kGuessLocale can enter an infinite loop

Details

There's regex logic that turns '.UTF-8' into '', and downstream there is logic checking if that value is falsey (instead of undefined).

As a result, kGuessLocale and locale call each other infinitely.

Todo

this.locale(locale.replace(/[.:].*/, ''))

This line is what converts '.UTF-8' into ''. I don't know if my fix is sufficient or if the real problem is here.

@@ -871,7 +871,7 @@ export class YargsInstance {
}
locale(locale?: string): YargsInstance | string {
argsert('[string]', [locale], arguments.length);
if (!locale) {
if (locale === undefined) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'' is falsey, and it causes the two functions to infinitely call each other

@jly36963 jly36963 requested a review from bcoe May 7, 2022 15:30
@bcoe bcoe merged commit b672e70 into yargs:main May 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants