Skip to content

fix: parse JSON cookies with falsy values - #172

Open
spokodev wants to merge 1 commit into
expressjs:masterfrom
spokodev:fix/json-cookies-falsy-values
Open

fix: parse JSON cookies with falsy values#172
spokodev wants to merge 1 commit into
expressjs:masterfrom
spokodev:fix/json-cookies-falsy-values

Conversation

@spokodev

@spokodev spokodev commented Sep 2, 2026

Copy link
Copy Markdown

JSONCookies() only writes the parsed value back when it is truthy (if (val)), so a cookie whose JSON payload is false, 0, null or "" is left as the raw j:-prefixed string instead of being inflated. The README states such values "will be exposed as the result of JSON.parse".

JSONCookie() already returns undefined only on parse failure, so guarding on val !== undefined preserves the "keep the original value on invalid JSON" behaviour while correctly parsing falsy values.

Refs #168.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant