From 865ac01937d1770095db22362c71b11af30e7de1 Mon Sep 17 00:00:00 2001 From: Tobie Langel Date: Mon, 15 Oct 2007 17:19:16 +0000 Subject: [PATCH] prototype: Make sure $w always returns an array. --- CHANGELOG | 2 ++ src/array.js | 1 + test/unit/array.html | 5 +++++ 3 files changed, 8 insertions(+) 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'));