bug with String.contains polyfill

Open Beginner friendly
#260 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
70/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
angularjs
Domain
frontend

Research direction

The issue is in the String.contains polyfill. Look for where String.prototype.contains is defined in the codebase, likely in a polyfill file. The fix is to use Object.defineProperty with enumerable: false to prevent the property from appearing in for...in loops. Test the fix by running the provided code snippet before and after the change to ensure the function is not enumerated and no exception is thrown.

Written by the indexing model from the issue text.

Description

Using and loving this library. Found a bug with the String.contains polyfill. Another library was calling a for in loop on a string and the contains function was showing as a property. That library was then calling the function anonymously which led to an exception being thrown. We included a fix in our code before importing your library and I'm sharing it with you if you are interested in applying it to this library:
if(!String.prototype.contains){
Object.defineProperty(String.prototype, 'contains', {
enumerable: false,
value: function() {
return String.prototype.indexOf.apply(this, arguments) !== -1;
}
});
}

You can test out the fix by running the following code before and after this fix:
for(var i in ''){ console.log(i);var fn = ''[i]; fn();}

Dominant language
JavaScript
Stars
2.9k
Forks
319
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from a8m/angular-filter

All issues in a8m/angular-filter

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.