Skip to content

Commit 453565e

Browse files
nervghyyx990803
authored andcommitted
Fixed: the "pluralize" filter with multi arguments, when selected argument is empty string (vuejs#3101)
1 parent 2aafe10 commit 453565e

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/filters/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,13 @@ export default {
104104

105105
pluralize (value) {
106106
var args = toArray(arguments, 1)
107-
return args.length > 1
108-
? (args[value % 10 - 1] || args[args.length - 1])
109-
: (args[0] + (value === 1 ? '' : 's'))
107+
var length = args.length
108+
if (length > 1) {
109+
var index = value % 10 - 1
110+
return index in args ? args[index] : args[length - 1]
111+
} else {
112+
return args[0] + (value === 1 ? '' : 's')
113+
}
110114
},
111115

112116
/**

test/unit/specs/filters/filters_spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ describe('Filters', function () {
5353
expect(filter(2, 'st', 'nd', 'rd', 'th')).toBe('nd')
5454
expect(filter(3, 'st', 'nd', 'rd', 'th')).toBe('rd')
5555
expect(filter(4, 'st', 'nd', 'rd', 'th')).toBe('th')
56+
// multi args where selected argument is empty string
57+
expect(filter(1, '', 'nd', 'rd', 'th')).toBe('')
5658
})
5759

5860
it('currency', function () {

0 commit comments

Comments
 (0)