Skip to content
This repository was archived by the owner on Apr 16, 2019. It is now read-only.
This repository was archived by the owner on Apr 16, 2019. It is now read-only.

CANNOT set the falsy values through $.data(). #609

@LeoYuan

Description

@LeoYuan

bug description

two bugs:

  1. if you want to set a falsy value(e.g. false, 0) through $.data() will never take effect, 'cause the if course inside which decide to set some value or not will never get executed.
  2. the $.data getter will accidently convert a number-like string to a number.

how to reproduce?

1.
$('body').data('key', true);    // output `true`
$('body').data('key', false);    // output `true`

2. 
$('body').data('anotherKey', '1');  // output 1

how to fix?

if (value) {  // wrong
if (value !== undefined && value !== null) {

what a shame, a pull request which created by me several months ago resulted in this error...^_^

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions