Bug: String.prototype.endsWith

David Herman dherman at mozilla.com
Fri Oct 7 06:38:50 PDT 2011


Fixed, thanks.

Dave, digging his way out of a massive backlog...

On Sep 23, 2011, at 12:18 PM, Axel Rauschmayer wrote:

> http://wiki.ecmascript.org/doku.php?id=harmony:string_extras
> I’ve found a small bug:
> 
> String.prototype.endsWith = function(s) {
>     var t = String(s);
>     return this.lastIndexOf(t) === this.length - t.length;
> };
> Interaction:
> > "".endsWith("/")
> true
> > "#".endsWith("//")
> true
> > "##".endsWith("///")
> true
> 
> Fix (e.g.):
> String.prototype.endsWith = function(s) {
>     var t = String(s);
>     var index = this.lastIndexOf(t)
>     return index >= 0 && index === this.length - t.length;
> };
> 
> 
> -- 
> Dr. Axel Rauschmayer
> 
> axel at rauschma.de
> twitter.com/rauschma
> 
> home: rauschma.de
> blog: 2ality.com
> 
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111007/40f0ead4/attachment.html>


More information about the es-discuss mailing list