From 4cafec8a9ce8f7d9e88e4be756c19cca14ab647d Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Thu, 31 May 2007 22:32:25 +0000 Subject: [PATCH] Prototype: String.prototype.truncate now explicitly converts its return value into a string if no truncation takes place. This prevents possible issues with methods expecting input data that is typeof == string. --- CHANGELOG | 2 ++ src/string.js | 2 +- test/unit/string.html | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index fe6572d..531481a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* String.prototype.truncate now explicitly converts its return value into a string if no truncation takes place. This prevents possible issues with methods expecting input data that is typeof == 'string'. [Thomas Fuchs, Tobie Langel, Sam Stephenson] + * Event.findElement behaves as expected when the element passed matches the given selector. Closes #8395. [Mislav Marohnić, Tobie Langel] * Element.setOpacity now calls removeAttribute on the filter style on IE if no more filters remain, which makes Cleartype work properly. Closes #8376. [alexdemi, Thomas Fuchs] diff --git a/src/string.js b/src/string.js index eb60795..d42b436 100644 --- a/src/string.js +++ b/src/string.js @@ -48,7 +48,7 @@ Object.extend(String.prototype, { length = length || 30; truncation = truncation === undefined ? '...' : truncation; return this.length > length ? - this.slice(0, length - truncation.length) + truncation : this; + this.slice(0, length - truncation.length) + truncation : String(this); }, strip: function() { diff --git a/test/unit/string.html b/test/unit/string.html index d46eec9..a1126c8 100644 --- a/test/unit/string.html +++ b/test/unit/string.html @@ -208,6 +208,9 @@ assertEqual('foo boo boz foo boo boz foo...', source.truncate(0)); assertEqual('fo...', source.truncate(5)); assertEqual('foo b', source.truncate(5, '')); + + assert(typeof 'foo'.truncate(5) == 'string'); + assert(typeof'foo bar baz'.truncate(5) == 'string'); }}, testStrip: function() {with(this) {