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

fix(ngPluralize): Handle the empty string as a valid override #2597

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ng/directive/ngPluralize.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ var ngPluralizeDirective = ['$locale', '$interpolate', function($locale, $interp
if (!isNaN(value)) {
//if explicit number rule such as 1, 2, 3... is defined, just use it. Otherwise,
//check it against pluralization rules in $locale service
if (!whens[value]) value = $locale.pluralCat(value - offset);
if (!(value in whens)) value = $locale.pluralCat(value - offset);
return whensExpFns[value](scope, element, true);
} else {
return '';
Expand Down
15 changes: 15 additions & 0 deletions test/ng/directive/ngPluralizeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ describe('ngPluralize', function() {
});


describe('edge cases', function() {
it('should be able to handle empty strings as possible values', inject(function($rootScope, $compile) {
element = $compile(
'<ng:pluralize count="email"' +
"when=\"{'0': ''," +
"'one': 'Some text'," +
"'other': 'Some text'}\">" +
'</ng:pluralize>')($rootScope);
$rootScope.email = '0';
$rootScope.$digest();
expect(element.text()).toBe('');
}));
});


describe('deal with pluralized strings with offset', function() {
it('should show single/plural strings with offset', inject(function($rootScope, $compile) {
element = $compile(
Expand Down