diff --git a/CHANGELOG b/CHANGELOG index d4f27c2..30d8787 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* String.prototype.endsWith should not fail on multiple occurrences. Closes #7416. [Christophe Porteneuve] + * Add Form.Methods.request as a convenience method for serializing and submitting a form via Ajax.Request to the URL in the form's action attribute. [sam] Options passed to request() are intelligently merged with the underlying Ajax.Request options: diff --git a/src/string.js b/src/string.js index 75e72f1..e3f10b3 100644 --- a/src/string.js +++ b/src/string.js @@ -151,7 +151,7 @@ Object.extend(String.prototype, { }, endsWith: function(pattern){ - return this.indexOf(pattern) == (this.length - pattern.length); + return this.lastIndexOf(pattern) == (this.length - pattern.length); } }); diff --git a/test/unit/string.html b/test/unit/string.html index 00829d0..80c9ddb 100644 --- a/test/unit/string.html +++ b/test/unit/string.html @@ -343,6 +343,7 @@ assert('hello world'.endsWith(' world')); assert(!'hello world'.endsWith('planet')); assert(!''.endsWith('planet')); + assert('hello world world'.endsWith(' world')); }}, testSucc: function() {with(this) {