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(service): check whether browserLang is undefined #1007

Merged
merged 1 commit into from
Feb 5, 2020
Merged

fix(service): check whether browserLang is undefined #1007

merged 1 commit into from
Feb 5, 2020

Conversation

cfilipponi
Copy link
Contributor

When accessing a non-existing property, JavaScript returns undefined.
The check for 'undefined' will guarantee that browserLang has been and we can safely call .indexOf()

When accessing a non-existing property, JavaScript returns undefined.
The check for 'undefined' will guarantee that browserLang has been and we can safely call .indexOf()
@cfilipponi
Copy link
Contributor Author

Another approach would be wrapping everything in a conditional like this:

if (browserLang) {
      if (browserLang.indexOf('-') !== -1) {
        browserLang = browserLang.split('-')[0];
      }

      if (browserLang.indexOf('_') !== -1) {
        browserLang = browserLang.split('_')[0];
      }
    }

@ocombe ocombe merged commit 3e0aebb into ngx-translate:master Feb 5, 2020
@ocombe ocombe changed the title fix(TranslateService): check whether variable contains undefined value fix(service): check whether browserLang is undefined Feb 5, 2020
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