jquery / jquery/api.jquery.com

Document jQuery.isEmptyObject doesn't take symbols into account

Open
#1,192 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
325
Forks
260
PR merge metrics
No merged PRs in 30d

Description

Description

On version 3.6.0, I found a vulnerability,I find that the method of detecting empty objects is not perfect.

isEmptyObject: function( obj ) {
  var name;

  for ( name in obj ) {
     return false;
   }
   return true;
},

The downside of writing this is that the properties of the prototype chain and the Symbol type are not taken into account,I have a better way to implement it as follows.

isEmptyObject: function( obj ) {
    var keys = Object.keys(obj);

    // 看浏览器是否支持 Symbol
    if (typeof Symbol !== "undefined") {
       keys = keys.concat(Object.getOwnPropertySymbols(obj));
    }
  
    return keys.length === 0;
}
Link to test case

This direct modification of the source code test is good, I do not have a service to run this test. I'm looking forward to hearing from you.

Contributor guide

Open the contributing guide

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.

Research direction

Start by locating the jQuery.isEmptyObject API documentation and compare its current description with the behavior described in the issue. Confirm whether the documentation should explain Symbol properties and prototype-chain properties, then update the relevant documentation and verify the rendered entry reflects the agreed behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
jquery
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.