From 6969c88a833f43f58fb0e52e0d8127968c6e1ab2 Mon Sep 17 00:00:00 2001 From: Rahul Doshi Date: Thu, 26 Feb 2015 11:27:24 -0800 Subject: [PATCH] fix(defaultLocale): setLocale fails on passing it invalid values 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 --- dist/angular-localization.js | 18 ++++++++++++++++-- dist/angular-localization.min.js | 4 ++-- dist/angular-localization.min.js.gz | Bin 2031 -> 2059 bytes dist/angular-localization.min.map | 2 +- src/localization.js | 16 +++++++++++++++- tests/unit/serviceSpec.js | 13 +++++++++++++ 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/dist/angular-localization.js b/dist/angular-localization.js index 3bdfd18..b1260cd 100644 --- a/dist/angular-localization.js +++ b/dist/angular-localization.js @@ -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 @@ -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 = {}; diff --git a/dist/angular-localization.min.js b/dist/angular-localization.min.js index eaad98a..1da13bb 100644 --- a/dist/angular-localization.min.js +++ b/dist/angular-localization.min.js @@ -1,9 +1,9 @@ /** - * 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 * License: MIT */ -!function(a){"use strict";a.module("ngLocalize.Config",[]).value("localeConf",{basePath:"languages",defaultLocale:"en-US",sharedDictionary:"common",fileExtension:".lang.json",persistSelection:!0,cookieName:"COOKIE_LOCALE_LANG",observableAttrs:new RegExp("^data-(?!ng-|i18n)"),delimiter:"::"}),a.module("ngLocalize.Events",[]).constant("localeEvents",{resourceUpdates:"ngLocalizeResourcesUpdated",localeChanges:"ngLocalizeLocaleChanged"}),a.module("ngLocalize",["ngSanitize","ngLocalize.Config","ngLocalize.Events","ngLocalize.InstalledLanguages"]).service("locale",["$injector","$http","$q","$log","$rootScope","$window","localeConf","localeEvents","localeSupported","localeFallbacks",function(b,c,d,e,f,g,h,i,j,k){function l(a){return a&&a.length&&new RegExp("^[\\w\\.-]+\\.[\\w\\.-]+\\w(:.*)?$").test(a)}function m(a){var b=a?a.split("."):"",c="";return b.length>1&&(c=b.slice(0,-1).join(".")),c}function n(a){var b=a?a.split("."):[],c="";return b.length&&(c=b[b.length-1]),c}function o(a){var b,c=null,d=a?a.split("."):[];if(d.length>1)for(c=y,b=0;b1){for(b=0;b1?(f=[],c.forEach(function(a){f.push(q(a))}),e=d.all(f)):e=q(b),e}function s(b,c){var d=b,e=0;return c&&(a.isArray(c)?a.forEach(c,function(a,b){d=d.replace("%"+(b+1),a),d=d.replace("{"+(b+1)+"}",a)}):a.forEach(c,function(a,b){++e,d=d.replace("{"+b+"}",a),d=d.replace("%"+b,a),d=d.replace("%"+e,a),d=d.replace("{"+e+"}",a)})),d=d.replace(/\n/g,"
")}function t(b,c){var d,f,g,i="",j=!1;return a.isString(b)&&!c&&-1!=b.indexOf(h.delimiter)&&(g=b.split(h.delimiter),b=g[0],c=a.fromJson(g[1])),j=l(b),j?(a.isObject(c)||(c=[c]),d=o(b),d&&!d._loading?(f=n(b),d[f]?i=s(d[f],c):(e.info("[localizationService] Key not found: "+b),i="%%KEY_NOT_FOUND%%")):d||p(b)):i=b,i}function u(a){var b=-1!=j.indexOf(a)?a:k[a.split("-")[0]]||h.defaultLocale;b!=w&&(y={},x={},w=b,f.$broadcast(i.localeChanges,w),f.$broadcast(i.resourceUpdates),z&&z.put(h.cookieName,b))}function v(){return w}var w,x,y,z;return h.persistSelection&&b.has("$cookieStore")&&(z=b.get("$cookieStore")),u(z?z.get(h.cookieName):g.navigator.userLanguage||g.navigator.language),{ready:r,isToken:l,getPath:m,getKey:n,setLocale:u,getLocale:v,getString:t}}]).filter("i18n",["locale",function(a){return function(b,c){return a.getString(b,c)}}]).directive("i18n",["$sce","locale","localeEvents","localeConf",function(b,c,d,e){function f(a,c){c!==a.html()&&a.html(b.getTrustedHtml(c))}function g(a,b,d){c.isToken(b)?c.ready(c.getPath(b)).then(function(){f(a,c.getString(b,d))}):f(a,b)}return function(b,c,f){var h;f.$observe("i18n",function(a,b){a&&a!=b&&g(c,a,h)}),a.forEach(f.$attr,function(a,b){e.observableAttrs.test(a)&&f.$observe(b,function(a,d){(a&&a!=d||!h||!h[b])&&(h=h||{},h[b]=f[b],g(c,f.i18n,h))})}),b.$on(d.resourceUpdates,function(){g(c,f.i18n,h)}),b.$on(d.localeChanges,function(){g(c,f.i18n,h)})}}]).directive("i18nAttr",["locale","localeEvents",function(a,b){return function(c,d,e){function f(b,d){var f,h=c.$eval(d),i=[];for(var j in h)f=h[j],a.isToken(f)&&-1==i.indexOf(a.getPath(f))&&i.push(a.getPath(f));a.ready(i).then(function(){var b="";for(var c in h)f=h[c],b=a.getString(f),g[c]!==b&&e.$set(c,g[c]=b)})}var g={};e.$observe("i18nAttr",function(a,b){a&&a!=b&&f(d,a)}),c.$on(b.resourceUpdates,function(){f(d,e.i18nAttr)}),c.$on(b.localeChanges,function(){f(d,e.i18nAttr)})}}]),a.module("ngLocalize.InstalledLanguages",[]).value("localeSupported",["en-US"]).value("localeFallbacks",{en:"en-US"}),a.module("ngLocalize.Version",[]).constant("localeVer","1.1.4")}(window.angular,window,document); +!function(a){"use strict";a.module("ngLocalize.Config",[]).value("localeConf",{basePath:"languages",defaultLocale:"en-US",sharedDictionary:"common",fileExtension:".lang.json",persistSelection:!0,cookieName:"COOKIE_LOCALE_LANG",observableAttrs:new RegExp("^data-(?!ng-|i18n)"),delimiter:"::"}),a.module("ngLocalize.Events",[]).constant("localeEvents",{resourceUpdates:"ngLocalizeResourcesUpdated",localeChanges:"ngLocalizeLocaleChanged"}),a.module("ngLocalize",["ngSanitize","ngLocalize.Config","ngLocalize.Events","ngLocalize.InstalledLanguages"]).service("locale",["$injector","$http","$q","$log","$rootScope","$window","localeConf","localeEvents","localeSupported","localeFallbacks",function(b,c,d,e,f,g,h,i,j,k){function l(a){return a&&a.length&&new RegExp("^[\\w\\.-]+\\.[\\w\\.-]+\\w(:.*)?$").test(a)}function m(a){var b=a?a.split("."):"",c="";return b.length>1&&(c=b.slice(0,-1).join(".")),c}function n(a){var b=a?a.split("."):[],c="";return b.length&&(c=b[b.length-1]),c}function o(a){var b,c=null,d=a?a.split("."):[];if(d.length>1)for(c=y,b=0;b1){for(b=0;b1?(f=[],c.forEach(function(a){f.push(q(a))}),e=d.all(f)):e=q(b),e}function s(b,c){var d=b,e=0;return c&&(a.isArray(c)?a.forEach(c,function(a,b){d=d.replace("%"+(b+1),a),d=d.replace("{"+(b+1)+"}",a)}):a.forEach(c,function(a,b){++e,d=d.replace("{"+b+"}",a),d=d.replace("%"+b,a),d=d.replace("%"+e,a),d=d.replace("{"+e+"}",a)})),d=d.replace(/\n/g,"
")}function t(b,c){var d,f,g,i="",j=!1;return a.isString(b)&&!c&&-1!=b.indexOf(h.delimiter)&&(g=b.split(h.delimiter),b=g[0],c=a.fromJson(g[1])),j=l(b),j?(a.isObject(c)||(c=[c]),d=o(b),d&&!d._loading?(f=n(b),d[f]?i=s(d[f],c):(e.info("[localizationService] Key not found: "+b),i="%%KEY_NOT_FOUND%%")):d||p(b)):i=b,i}function u(b){var c;a.isString(b)?(b=b.trim(),-1!=j.indexOf(b)?c=b:(c=k[b.split("-")[0]],a.isUndefined(c)&&(c=h.defaultLocale))):c=h.defaultLocale,c!=w&&(y={},x={},w=c,f.$broadcast(i.localeChanges,w),f.$broadcast(i.resourceUpdates),z&&z.put(h.cookieName,c))}function v(){return w}var w,x,y,z;return h.persistSelection&&b.has("$cookieStore")&&(z=b.get("$cookieStore")),u(z?z.get(h.cookieName):g.navigator.userLanguage||g.navigator.language),{ready:r,isToken:l,getPath:m,getKey:n,setLocale:u,getLocale:v,getString:t}}]).filter("i18n",["locale",function(a){return function(b,c){return a.getString(b,c)}}]).directive("i18n",["$sce","locale","localeEvents","localeConf",function(b,c,d,e){function f(a,c){c!==a.html()&&a.html(b.getTrustedHtml(c))}function g(a,b,d){c.isToken(b)?c.ready(c.getPath(b)).then(function(){f(a,c.getString(b,d))}):f(a,b)}return function(b,c,f){var h;f.$observe("i18n",function(a,b){a&&a!=b&&g(c,a,h)}),a.forEach(f.$attr,function(a,b){e.observableAttrs.test(a)&&f.$observe(b,function(a,d){(a&&a!=d||!h||!h[b])&&(h=h||{},h[b]=f[b],g(c,f.i18n,h))})}),b.$on(d.resourceUpdates,function(){g(c,f.i18n,h)}),b.$on(d.localeChanges,function(){g(c,f.i18n,h)})}}]).directive("i18nAttr",["locale","localeEvents",function(a,b){return function(c,d,e){function f(b,d){var f,h=c.$eval(d),i=[];for(var j in h)f=h[j],a.isToken(f)&&-1==i.indexOf(a.getPath(f))&&i.push(a.getPath(f));a.ready(i).then(function(){var b="";for(var c in h)f=h[c],b=a.getString(f),g[c]!==b&&e.$set(c,g[c]=b)})}var g={};e.$observe("i18nAttr",function(a,b){a&&a!=b&&f(d,a)}),c.$on(b.resourceUpdates,function(){f(d,e.i18nAttr)}),c.$on(b.localeChanges,function(){f(d,e.i18nAttr)})}}]),a.module("ngLocalize.InstalledLanguages",[]).value("localeSupported",["en-US"]).value("localeFallbacks",{en:"en-US"}),a.module("ngLocalize.Version",[]).constant("localeVer","1.1.4")}(window.angular,window,document); //# sourceMappingURL=angular-localization.min.map \ No newline at end of file diff --git a/dist/angular-localization.min.js.gz b/dist/angular-localization.min.js.gz index 819003ad9c7a46ddc786422a21be5f0704250677..6f7c4741f22885ff09d68ee4ba732b296e003b86 100644 GIT binary patch literal 2059 zcmV+m2=w&L09;^z}>rzxzAwUuefN!lIbx)?g4sMOZr0O=kly&BJ+?&gRA7 zm`EI@(;w3LQx*kbVVEwjBpWN^y9&$L_y_?J?YWFxo#fgw{`mX@bVk*95 zWv-39$Rf93BPD04SH{|8NpM+f)AB=__));bc*5m_ic73kmS|dFV(F+{e^W(hv6w7X zfzFxmw6DszsDx;X>7;*i%|srmOnV=rO1sLQEQYJj(u4^=iuJ`~0YkB3F-fB2G^eGx z&hjWPu63-dbJoe3aMScY(qGjKvOip1effNGcX{>U{U!dr|N1)I0Uldtx zC3<0e*TKc(++_dtRH6Fj`AHJ=SJChv31=Mk#?dS)bY?NjVrwpry5izNCq-Vn!cCLB zP)V`%#&&I)={zknSKrK`Nat2d!1v8kUaxsfY&;p_y8Bx%TMOQ62Eh`Hu2m8h)#zB* zj@jRy`%Kq}W9?lw(ZlV?eZbB3a-^seB~wHo&2YX$h^7BO=_gJ}PbW*$;@VB;WJqTb zC0@F~QyVJ>uG$Q*%lSObDtByVKEWVIx%b%9VAT<>@Prn=2t+6%F%|cGxm`74!g8jI zGD{5A?J61TBq+jecQ5ke+uOzMt?W;F_-zjsrX}C<^A6(@AuAwk-H4u%=m(V z%;#~0pi9Or#)NA#HrnWQHcEdRcDtr)J2H>Sg=eBa>BG?wnJ>n6r40K^mf&bD)n&##Xe)WBTL7MjEKWNkAYc6$`L2qLeU+T>i8@H>&b)CHvs{=AwlK7XpR(0z6;`bL2@(M=)ngKzd-dh!+Z_XTQrsG5D~byJvptC#pfeMIce>pZ zr_pv!%gwbEx17~#zCA6e=0&;QnUn2YkK`weC>iC~s8~sWC0-?3jV{6XNXNOZKuf#c zXPJ7UO+}cc3xl}eqIOr!Gq6H=Pe!JHmJtjxH0rO;P{WPtq>(}^3Y6;Sd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r(z_pWCmOKW;x=UVr^~a)SC|d6Z88y%hmD(avqW{ooxKxExb8kQa~ zj$=1`woTWg^Odq<1>8VgaF5hdiezgwjexuD8u`NiR3g_w-x? z*DBU)G-9YvfTGE$QKc?y+mE%GW#ff*tF&u|WFxV9UkUZVc32AfZRB=yS2z9FYn@u% z#T~X}tu_o;BHeDsM#_Z6JT^HsW7SjT_8(c9gGT>JFWh#B10opVVXxfy4G=zaYlb$f zx=b!4TuYF2(k_CP*1dCjM6s4%k=FW%dxT$SLO2FG>&rspi+#qUW)j5F>jfY~B|=`c z;tjvcuEGW5V2_pu_m6E;+3U5`Iqh9IxLK=0_I5)0pnD;_hBih>H5%JKz64p~OEMPb zz#drSKx|@qhsh;cPTJem+OnUouWvX896DSZln1EU_sU@yUSg+;KZV5?q3z19#&r{Y z4~Py;D>Ym+H>0L2cXWwD_Dj-nOG1tu>%QjqUZKy8iCH#f`THSo9KAHB+Jm z-)eSun%yaCLp!y6^q+VO+yg3Fc9GsVVBG_f^Jsqn#vJPdywxsz1#{?!tEvceQ?Q)> z6<=Db=Qn#D~jePvKH^brIjoN*Gs>K3PyZ(M*ANzAf&Le!( N;xFL+cyrSc002K{|8oEU diff --git a/dist/angular-localization.min.map b/dist/angular-localization.min.map index 21c161f..46b66c1 100644 --- a/dist/angular-localization.min.map +++ b/dist/angular-localization.min.map @@ -1 +1 @@ -{"version":3,"file":"angular-localization.min.js","sources":["angular-localization.js"],"names":["angular","module","value","basePath","defaultLocale","sharedDictionary","fileExtension","persistSelection","cookieName","observableAttrs","RegExp","delimiter","constant","resourceUpdates","localeChanges","service","$injector","$http","$q","$log","$rootScope","$window","localeConf","localeEvents","localeSupported","localeFallbacks","isToken","str","length","test","getPath","tok","path","split","result","slice","join","getKey","getBundle","i","bundles","loadBundle","token","root","url","currentLocale","_loading","get","success","data","key","hasOwnProperty","$broadcast","deferrences","resolve","error","bundleReady","bundle","langFile","defer","promise","ready","paths","deferred","outstanding","isString","isArray","Error","forEach","push","all","applySubstitutions","text","subs","res","firstOfKind","sub","replace","v","k","getLocalizedString","txt","A","isValidToken","indexOf","fromJson","isObject","info","setLocale","lang","cookieStore","put","getLocale","has","navigator","userLanguage","language","getString","filter","locale","input","args","directive","$sce","setText","elm","tag","html","getTrustedHtml","update","string","optArgs","then","scope","attrs","hasObservers","$observe","newVal","oldVal","$attr","attr","normAttr","i18n","$on","elem","updateText","target","attributes","exp","values","$eval","langFiles","lastValues","$set","i18nAttr","en","window","document"],"mappings":";;;;;;;CAOC,SAAWA,GACR,YACJA,GAAQC,OAAO,wBACVC,MAAM,cACHC,SAAU,YACVC,cAAe,QACfC,iBAAkB,SAClBC,cAAe,aACfC,kBAAkB,EAClBC,WAAY,qBACZC,gBAAiB,GAAIC,QAAO,sBAC5BC,UAAW,OAEnBX,EAAQC,OAAO,wBACVW,SAAS,gBACNC,gBAAiB,6BACjBC,cAAe,4BAEvBd,EAAQC,OAAO,cAAe,aAAc,oBAAqB,oBAAqB,kCACjFc,QAAQ,UAAW,YAAa,QAAS,KAAM,OAAQ,aAAc,UAAW,aAAc,eAAgB,kBAAmB,kBAC9H,SAAUC,EAAWC,EAAOC,EAAIC,EAAMC,EAAYC,EAASC,EAAYC,EAAcC,EAAiBC,GAUlG,QAASC,GAAQC,GACb,MAAQA,IAAOA,EAAIC,QAAU,GAAIlB,QAAO,sCAAsCmB,KAAKF,GAGvF,QAASG,GAAQC,GACb,GAAIC,GAAOD,EAAMA,EAAIE,MAAM,KAAO,GAC9BC,EAAS,EAMb,OAJIF,GAAKJ,OAAS,IACdM,EAASF,EAAKG,MAAM,EAAG,IAAIC,KAAK,MAG7BF,EAGX,QAASG,GAAON,GACZ,GAAIC,GAAOD,EAAMA,EAAIE,MAAM,QACvBC,EAAS,EAMb,OAJIF,GAAKJ,SACLM,EAASF,EAAKA,EAAKJ,OAAS,IAGzBM,EAGX,QAASI,GAAUP,GACf,GAEIQ,GAFAL,EAAS,KACTF,EAAOD,EAAMA,EAAIE,MAAM,OAG3B,I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EAAMoB,YAE3BrB,EAAMU,IAAIpG,EAAaT,cAAe,WAClC+G,EAAWD,EAAMV,EAAMoB,gBAK3CtI,EAAQC,OAAO,oCACVC,MAAM,mBACH,UAEHA,MAAM,mBACHqI,GAAM,UAEdvI,EAAQC,OAAO,yBACVW,SAAS,YAAa,UACxB4H,OAAOxI,QAASwI,OAAQC","sourceRoot":"/Users/r.doshi/Projects/angular-localization"} \ No newline at end of file +{"version":3,"file":"angular-localization.min.js","sources":["angular-localization.js"],"names":["angular","module","value","basePath","defaultLocale","sharedDictionary","fileExtension","persistSelection","cookieName","observableAttrs","RegExp","delimiter","constant","resourceUpdates","localeChanges","service","$injector","$http","$q","$log","$rootScope","$window","localeConf","localeEvents","localeSupported","localeFallbacks","isToken","str","length","test","getPath","tok","path","split","result","slice","join","getKey","getBundle","i","bundles","loadBundle","token","root","url","currentLocale","_loading","get","success","data","key","hasOwnProperty","$broadcast","deferrences","resolve","error","bundleReady","bundle","langFile","defer","promise","ready","paths","deferred","outstanding","isString","isArray","Error","forEach","push","all","applySubstitutions","text","subs","res","firstOfKind","sub","replace","v","k","getLocalizedString","txt","A","isValidToken","indexOf","fromJson","isObject","info","setLocale","lang","trim","isUndefined","cookieStore","put","getLocale","has","navigator","userLanguage","language","getString","filter","locale","input","args","directive","$sce","setText","elm","tag","html","getTrustedHtml","update","string","optArgs","then","scope","attrs","hasObservers","$observe","newVal","oldVal","$attr","attr","normAttr","i18n","$on","elem","updateText","target","attributes","exp","values","$eval","langFiles","lastValues","$set","i18nAttr","en","window","document"],"mappings":";;;;;;;CAOC,SAAWA,GACR,YACJA,GAAQC,OAAO,wBACVC,MAAM,cACHC,SAAU,YACVC,cAAe,QACfC,iBAAkB,SAClBC,cAAe,aACfC,kBAAkB,EAClBC,WAAY,qBACZC,gBAAiB,GAAIC,QAAO,sBAC5BC,UAAW,OAEnBX,EAAQC,OAAO,wBACVW,SAAS,gBACNC,gBAAiB,6BACjBC,cAAe,4BAEvBd,EAAQC,OAAO,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E5BF,EAAMU,IAAItG,EAAaT,cAAe,WAClCiG,EAAOJ,EAAKS,EAAMQ,KAAMP,SAKvCb,UAAU,YAAa,SAAU,eAC9B,SAAUH,EAAQ9E,GACd,MAAO,UAAU4F,EAAOW,EAAMV,GAG1B,QAASW,GAAWC,EAAQC,GACxB,GAEIC,GAFAC,EAAShB,EAAMiB,MAAMH,GACrBI,IAGJ,KAAI,GAAInF,KAAOiF,GACXD,EAAMC,EAAOjF,GACTmD,EAAO3E,QAAQwG,IAAkD,IAA1CG,EAAUjD,QAAQiB,EAAOvE,QAAQoG,KACxDG,EAAUhE,KAAKgC,EAAOvE,QAAQoG,GAItC7B,GAAOxC,MAAMwE,GAAWnB,KAAK,WACzB,GAAIhH,GAAQ,EAEZ,KAAI,GAAIgD,KAAOiF,GACXD,EAAMC,EAAOjF,GACbhD,EAAQmG,EAAOF,UAAU+B,GACrBI,EAAWpF,KAAShD,GACpBkH,EAAMmB,KAAKrF,EAAKoF,EAAWpF,GAAOhD,KArBlD,GAAIoI,KA2BJlB,GAAME,SAAS,WAAY,SAAUC,EAAQC,GACrCD,GAAUA,GAAUC,GACpBO,EAAWD,EAAMP,KAIzBJ,EAAMU,IAAItG,EAAaV,gBAAiB,WACpCkH,EAAWD,EAAMV,EAAMoB,YAE3BrB,EAAMU,IAAItG,EAAaT,cAAe,WAClCiH,EAAWD,EAAMV,EAAMoB,gBAK3CxI,EAAQC,OAAO,oCACVC,MAAM,mBACH,UAEHA,MAAM,mBACHuI,GAAM,UAEdzI,EAAQC,OAAO,yBACVW,SAAS,YAAa,UACxB8H,OAAO1I,QAAS0I,OAAQC","sourceRoot":"/Users/r.doshi/Projects/angular-localization"} \ No newline at end of file diff --git a/src/localization.js b/src/localization.js index 65ce7de..7e88352 100644 --- a/src/localization.js +++ b/src/localization.js @@ -227,7 +227,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 = {}; diff --git a/tests/unit/serviceSpec.js b/tests/unit/serviceSpec.js index a13c2ea..00b4de7 100644 --- a/tests/unit/serviceSpec.js +++ b/tests/unit/serviceSpec.js @@ -18,5 +18,18 @@ describe('service', function () { locale.ready('common'); $httpBackend.flush(); })); + + it('should not error on calling setLocale with an invalid value', inject(function(locale) { + locale.setLocale(); + expect(locale.getLocale()).toBe('en-US'); + locale.setLocale('abc123'); + expect(locale.getLocale()).toBe('en-US'); + locale.setLocale({}); + expect(locale.getLocale()).toBe('en-US'); + locale.setLocale(''); + expect(locale.getLocale()).toBe('en-US'); + locale.setLocale(' '); + expect(locale.getLocale()).toBe('en-US'); + })); }); }); \ No newline at end of file