diff --git a/CHANGELOG b/CHANGELOG index 20a2e7e..02ab5c1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Make sure $w always returns an array. [Andrew Dupont, Tobie Langel] + * Add more tests to Hash. [Mislav Marohnić] * Performance enhancements to $A. Closes #9464. [Samuel Lebeau] diff --git a/src/array.js b/src/array.js index 499a42f..41fc895 100644 --- a/src/array.js +++ b/src/array.js @@ -128,6 +128,7 @@ if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i Array.prototype.toArray = Array.prototype.clone; function $w(string) { + if (!Object.isString(string)) return []; string = string.strip(); return string ? string.split(/\s+/) : []; } diff --git a/test/unit/array.html b/test/unit/array.html index 8e0973b..95de657 100644 --- a/test/unit/array.html +++ b/test/unit/array.html @@ -204,6 +204,11 @@ test$w: function(){ with(this) { assertEnumEqual(['a', 'b', 'c', 'd'], $w('a b c d')); assertEnumEqual([], $w(' ')); + assertEnumEqual([], $w('')); + assertEnumEqual([], $w(null)); + assertEnumEqual([], $w(undefined)); + assertEnumEqual([], $w()); + assertEnumEqual([], $w(10)); assertEnumEqual(['a'], $w('a')); assertEnumEqual(['a'], $w('a ')); assertEnumEqual(['a'], $w(' a'));