Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 6473

Show
Ignore:
Timestamp:
03/27/07 17:43:30 (1 year ago)
Author:
madrobby
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/trunk/CHANGELOG

    r6393 r6473  
     1*SVN* 
     2 
     3* Fix an issue with String.prototype.endsWith.  Closes #7822.  [altblue] 
     4 
    15*1.5.1_rc2* (March 12, 2007) 
    26 
  • spinoffs/prototype/trunk/src/string.js

    r6368 r6473  
    177177 
    178178  startsWith: function(pattern) { 
    179     return this.indexOf(pattern) == 0; 
     179    return this.indexOf(pattern) === 0; 
    180180  }, 
    181181 
    182182  endsWith: function(pattern) { 
    183     return this.lastIndexOf(pattern) == (this.length - pattern.length); 
     183    var d = this.length - pattern.length; 
     184    return d >= 0 && this.lastIndexOf(pattern) === d; 
    184185  }, 
    185186   
  • spinoffs/prototype/trunk/test/unit/string.html

    r6363 r6473  
    343343      assert(!'hello world'.startsWith('bye')); 
    344344      assert(!''.startsWith('bye')); 
     345      assert(!'hell'.startsWith('hello')); 
    345346    }}, 
    346347     
     
    351352      assert(!''.endsWith('planet')); 
    352353      assert('hello world world'.endsWith(' world')); 
     354      assert(!'z'.endsWith('az')); 
    353355    }}, 
    354356