Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/parser/string-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module.exports = {
throw new Error(`${substr} is not a string.`);
}

return str.indexOf(substr) + substr.length === str.length;
const strSuffix = str.substring(str.length - substr.length, str.length)
return strSuffix === substr
},

replace(str, substr, replacement) {
Expand Down
2 changes: 2 additions & 0 deletions test/spec/lib/parser/string-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ describe('stringMethods', function() {

it('returns true if the given string ends with the given substring', function() {
expect(stringMethods.endsWith('bar', 'ar')).to.be.true();
expect(stringMethods.endsWith('arbar', 'ar')).to.be.true();
});

it('returns false if the given string does not end with the given substring', function() {
expect(stringMethods.endsWith('bar', 'az')).to.be.false();
expect(stringMethods.endsWith('', 'az')).to.be.false();
});

});
Expand Down