fix: treat null and undefined as equal in IS_PRESENT computation (NIL equality) - #47
Draft
sd-gh-bot wants to merge 1 commit into
Draft
fix: treat null and undefined as equal in IS_PRESENT computation (NIL equality)#47sd-gh-bot wants to merge 1 commit into
sd-gh-bot wants to merge 1 commit into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User description
Root Cause
In the Computation Library, IS_PRESENT checks use
!= NILwhereNILis an undefined variable in the LiquidJS scope (it resolves toundefined).When Django sends
nullfor a never-filled questionnaire field (e.g., a Discount column), the comparisonnull != NIL(undefined)evaluated totruebecause JavaScript strict equalitynull !== 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
defaultHandlerinequals.jsto treatnullandundefinedas equivalent (both are 'nil'). Aligns with theisTruthy/isFalsysemantics already used in the LiquidJSiftag.Version Bump
3.1.0 → 3.1.1. After merging, update
@spotdraft/liquidjsdependency in cfexporter to3.1.1.Generated description
Below is a concise technical summary of the changes proposed in this PR:
Align
defaultHandlerinequals.jswith LiquidJS nil semantics sonullandundefinedcompare 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.defaultHandlerto treatnullandundefinedas equal and reinforce the behavior with nil-equality tests so IS_PRESENT stops flagging untouched questionnaire fields as present.Modified files (2)
Latest Contributors(2)
Modified files (1)
Latest Contributors(2)