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.

This commit is contained in:
Thomas Fuchs 2007-05-31 22:32:25 +00:00
parent b61bca10da
commit 4cafec8a9c
3 changed files with 6 additions and 1 deletions

View File

@ -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]

View File

@ -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() {

View File

@ -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) {