Skip to content

Commit

Permalink
fix(defaultLocale): setLocale fails on passing it invalid values
Browse files Browse the repository at this point in the history
introduce defensive checks in setLocale as a publicly exposed method
previously, an error was generated caused by a failure in setLocale
on new clients as cookie wasn't present and `undefined` was passed to it.
also added test cases to validate the same for future regressions.

closes #32
  • Loading branch information
doshprompt committed Feb 26, 2015
1 parent b69d76b commit 6969c88
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 6 deletions.
18 changes: 16 additions & 2 deletions dist/angular-localization.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* angular-localization :: v1.1.4 :: 2015-02-25
* angular-localization :: v1.1.4 :: 2015-02-26
* web: https://github.com/doshprompt/angular-localization
*
* Copyright (c) 2015 | Rahul Doshi
Expand Down Expand Up @@ -252,7 +252,21 @@ angular.module('ngLocalize', ['ngSanitize', 'ngLocalize.Config', 'ngLocalize.Eve
}

function setLocale(value) {
var lang = localeSupported.indexOf(value) != -1 ? value : localeFallbacks[value.split('-')[0]] || localeConf.defaultLocale;
var lang;

if (angular.isString(value)) {
value = value.trim();
if (localeSupported.indexOf(value) != -1) {
lang = value;
} else {
lang = localeFallbacks[value.split('-')[0]]
if (angular.isUndefined(lang)) {
lang = localeConf.defaultLocale;
}
}
} else {
lang = localeConf.defaultLocale;
}

if (lang != currentLocale) {
bundles = {};
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-localization.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/angular-localization.min.js.gz
Binary file not shown.
Loading

0 comments on commit 6969c88

Please sign in to comment.