Handle invalid input to list filter functions safely.
Previously list filter functions did not handle invalid input safely. This adds a check for null or undefined input and returns a default safe value. Change-Id: I59ea3be8b3d8413851204046890121bda3a44e04
This commit is contained in:
@@ -3,36 +3,64 @@
|
|||||||
var filtersModule = require('./_index.js');
|
var filtersModule = require('./_index.js');
|
||||||
|
|
||||||
var split = function(input, delim) {
|
var split = function(input, delim) {
|
||||||
|
if (typeof input === 'undefined' || input === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
delim = delim || ',';
|
delim = delim || ',';
|
||||||
|
|
||||||
return input.split(delim);
|
return input.split(delim);
|
||||||
};
|
};
|
||||||
|
|
||||||
var join = function(input, delim) {
|
var join = function(input, delim) {
|
||||||
|
if (typeof input === 'undefined' || input === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
delim = delim || ', ';
|
delim = delim || ', ';
|
||||||
|
|
||||||
return input.join(delim);
|
return input.join(delim);
|
||||||
};
|
};
|
||||||
|
|
||||||
var pick = function(input, index) {
|
var pick = function(input, index) {
|
||||||
|
if (typeof input === 'undefined' || input === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return input[index];
|
return input[index];
|
||||||
};
|
};
|
||||||
|
|
||||||
var pickRight = function(input, index) {
|
var pickRight = function(input, index) {
|
||||||
|
if (typeof input === 'undefined' || input === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
return input[input.length - index];
|
return input[input.length - index];
|
||||||
};
|
};
|
||||||
|
|
||||||
var slice = function(input, begin, end) {
|
var slice = function(input, begin, end) {
|
||||||
|
if (typeof input === 'undefined' || input === null) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
return input.slice(begin, end);
|
return input.slice(begin, end);
|
||||||
};
|
};
|
||||||
|
|
||||||
var first = function(input, length) {
|
var first = function(input, length) {
|
||||||
|
if (typeof input === 'undefined' || input === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
length = length || 1;
|
length = length || 1;
|
||||||
|
|
||||||
return input.slice(0, input.length - length);
|
return input.slice(0, input.length - length);
|
||||||
};
|
};
|
||||||
|
|
||||||
var last = function(input, length) {
|
var last = function(input, length) {
|
||||||
|
if (typeof input === 'undefined' || input === null) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
length = length || 1;
|
length = length || 1;
|
||||||
|
|
||||||
return input.slice(input.length - length, input.length);
|
return input.slice(input.length - length, input.length);
|
||||||
|
Reference in New Issue
Block a user