Skip to content

fix(utils): use strict null check in jsonUtils safeParseJson to preserve JSON primitives #57

Description

@tmdeveloper007

Summary of What Needs to be Done

src/utils/jsonUtils.js — the safeParseJson function uses if (!jsonString) return fallback;. The ! (falsy) check incorrectly rejects valid JSON primitive strings like "false", "0", and "null" because those values are falsy in JavaScript.

Changes

Change the guard from if (!jsonString) to if (jsonString === null || jsonString === undefined), preserving JSON primitive strings as valid inputs that should be parsed.

Impact

  • Silent data loss: Valid JSON strings that happen to be primitive values ("false", "0", "null") are silently discarded and replaced with the fallback, which could cause bugs in code that expects those parsed values.
  • This is a semantic bug — the function claims to safely parse JSON but actually destroys valid input.

Please assign this task to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    gssoc:approvedApproved for GSSoC contributionlevel:beginnerSmall, low-risk change (≤3 files, ≤50 lines)type:bugSomething is broken or incorrect

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions