Skip to content

fix: treat null and undefined as equal in IS_PRESENT computation (NIL equality) - #47

Draft
sd-gh-bot wants to merge 1 commit into
masterfrom
fix/null-nil-equality-in-is-present-computation
Draft

fix: treat null and undefined as equal in IS_PRESENT computation (NIL equality)#47
sd-gh-bot wants to merge 1 commit into
masterfrom
fix/null-nil-equality-in-is-present-computation

Conversation

@sd-gh-bot

@sd-gh-bot sd-gh-bot commented Jun 23, 2026

Copy link
Copy Markdown

User description

Root Cause

In the Computation Library, IS_PRESENT checks use != NIL where NIL is an undefined variable in the LiquidJS scope (it resolves to undefined).

When Django sends null for a never-filled questionnaire field (e.g., a Discount column), the comparison null != NIL(undefined) evaluated to true because JavaScript strict equality null !== undefined. This caused the Computation Library IS_PRESENT check to incorrectly report blank fields as 'present', making Docx columns appear even when no value was entered.

Fix

Change defaultHandler in equals.js to treat null and undefined as equivalent (both are 'nil'). Aligns with the isTruthy/isFalsy semantics already used in the LiquidJS if tag.

Version Bump

3.1.0 → 3.1.1. After merging, update @spotdraft/liquidjs dependency in cfexporter to 3.1.1.


Generated description

Below is a concise technical summary of the changes proposed in this PR:
Align defaultHandler in equals.js with LiquidJS nil semantics so null and undefined compare as equal, preventing blank questionnaire fields from being reported as present. Bump the package to 3.1.1 so downstream consumers can pick up the nil equality fix.

TopicDetails
NIL equality Adjust defaultHandler to treat null and undefined as equal and reinforce the behavior with nil-equality tests so IS_PRESENT stops flagging untouched questionnaire fields as present.
Modified files (2)
  • sd-custom/custom-operator/equals.js
  • test/sd-custom/custom-operator/equals.js
Latest Contributors(2)
UserCommitDate
neo@spotdraft.comfix: treat null and un...June 23, 2026
sanket0896@users.norep...use default liquidjs h...April 27, 2022
Release bump Publish version 3.1.1 so downstream consumers can adopt the nil-equality behavior.
Modified files (1)
  • package.json
Latest Contributors(2)
UserCommitDate
neo@spotdraft.comfix: treat null and un...June 23, 2026
sumanth-spotdraftAllow date and term ca...March 31, 2020
Review this PR on Baz | Customize your next review

…tion

The custom equality operator used strict JavaScript equality (===).
In the Computation Library, IS_PRESENT checks use '!= NIL' where NIL
resolves to undefined (an undefined variable in scope). When Django
sends null for a never-filled questionnaire field, the comparison
  null != NIL(undefined)
evaluated to true (null !== undefined) — incorrectly marking the
blank field as 'present'.

This caused blank questionnaire fields (e.g., a Discount column) to
appear in the generated Docx even when no value was entered.

Fix: In defaultHandler(), treat null and undefined as equivalent:
  - null == null  → true  (no change)
  - null == undefined → true  (fix: was false)
  - 0 == null     → false (no change)
  - false == null → false (no change)
  - '' == null    → false (no change)

This aligns with the isTruthy/isFalsy semantics already used in the
'if' tag evaluation and the LiquidJS runtime, where null and undefined
are both considered 'nil'.

Affected field types: NUMBER, TEXT, DROPDOWN, CHECKBOX, CURRENCY,
DURATION (any type relying on '!= NIL' in IS_PRESENT computations).

Bumps version to 3.1.1.

Co-authored-by: Shreekaran Gandikota <shreekaran@spotdraft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant