Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 67a4a25

Browse files
lgalfasopetebacondarwin
authored andcommitted
fix(ngPluralize): handle the empty string as a valid override
Fix the check for overrides so it is able to handle the empty string Closes #2575
1 parent f6caab5 commit 67a4a25

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/ng/directive/ngPluralize.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
194194
if (!isNaN(value)) {
195195
//if explicit number rule such as 1, 2, 3... is defined, just use it. Otherwise,
196196
//check it against pluralization rules in $locale service
197-
if (!whens[value]) value = $locale.pluralCat(value - offset);
197+
if (!(value in whens)) value = $locale.pluralCat(value - offset);
198198
return whensExpFns[value](scope, element, true);
199199
} else {
200200
return '';

test/ng/directive/ngPluralizeSpec.js

+15
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ describe('ngPluralize', function() {
9999
});
100100

101101

102+
describe('edge cases', function() {
103+
it('should be able to handle empty strings as possible values', inject(function($rootScope, $compile) {
104+
element = $compile(
105+
'<ng:pluralize count="email"' +
106+
"when=\"{'0': ''," +
107+
"'one': 'Some text'," +
108+
"'other': 'Some text'}\">" +
109+
'</ng:pluralize>')($rootScope);
110+
$rootScope.email = '0';
111+
$rootScope.$digest();
112+
expect(element.text()).toBe('');
113+
}));
114+
});
115+
116+
102117
describe('deal with pluralized strings with offset', function() {
103118
it('should show single/plural strings with offset', inject(function($rootScope, $compile) {
104119
element = $compile(

0 commit comments

Comments
 (0)