Skip to content

fix: prevent infinite loop with locale#2179

Merged
bcoe merged 2 commits intoyargs:mainfrom
jly36963:fix-locale-infinite-loop
May 15, 2022
Merged

fix: prevent infinite loop with locale#2179
bcoe merged 2 commits intoyargs:mainfrom
jly36963:fix-locale-infinite-loop

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.

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
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.

2 participants