Fix an issue with String.prototype.endsWith. Closes #7822. [altblue]

This commit is contained in:
Thomas Fuchs 2007-03-27 17:43:30 +00:00
parent 63985a21ed
commit fc91a3e456
3 changed files with 9 additions and 2 deletions

View File

@ -1,3 +1,7 @@
*SVN*
* Fix an issue with String.prototype.endsWith. Closes #7822. [altblue]
*1.5.1_rc2* (March 12, 2007)
* Add a tab character via innerHTML to the selector whitespace test. [Christophe Porteneuve]

View File

@ -176,11 +176,12 @@ Object.extend(String.prototype, {
},
startsWith: function(pattern) {
return this.indexOf(pattern) == 0;
return this.indexOf(pattern) === 0;
},
endsWith: function(pattern) {
return this.lastIndexOf(pattern) == (this.length - pattern.length);
var d = this.length - pattern.length;
return d >= 0 && this.lastIndexOf(pattern) === d;
},
empty: function() {

View File

@ -342,6 +342,7 @@
assert('hello world'.startsWith('hello'));
assert(!'hello world'.startsWith('bye'));
assert(!''.startsWith('bye'));
assert(!'hell'.startsWith('hello'));
}},
testEndsWith: function() {with(this) {
@ -350,6 +351,7 @@
assert(!'hello world'.endsWith('planet'));
assert(!''.endsWith('planet'));
assert('hello world world'.endsWith(' world'));
assert(!'z'.endsWith('az'));
}},
testBlank: function() { with(this) {