Skip to content

fix: guard against null/undefined in getTag function#251

Merged
nadeem-cs merged 2 commits intodevelopmentfrom
fix/DX-3657
Feb 13, 2026
Merged

fix: guard against null/undefined in getTag function#251
nadeem-cs merged 2 commits intodevelopmentfrom
fix/DX-3657

Conversation

@nadeem-cs
Copy link
Contributor

@nadeem-cs nadeem-cs commented Feb 12, 2026

Summary

  • Fixes #193addEditableTags throws TypeError: Cannot convert undefined or null to object when getTag receives null as the content parameter
  • Adds a null guard (content == null) at the top of the getTag function to return an empty object early, preventing Object.entries(null) from throwing
  • Adds 6 new test cases covering: null/undefined field values, null/undefined entries, multiple null fields, and nested null objects

Root Cause

In JavaScript, typeof null === "object" evaluates to true. When a field value is null, the switch (typeof value) in getTag matches case "object", and the recursive call to getTag(value, ...) passes null as the content parameter. This causes Object.entries(null) to throw a TypeError.

Test plan

  • Existing tests pass (34/34)
  • New tests cover null entry, undefined entry, null field values, undefined field values, multiple null fields, and nested null objects
  • Verified the exact reproduction case from the issue (getTag(null, 'some.prefix', true, 'en-us', { ...appliedVariants })) no longer throws

- Add null check at the top of getTag to return empty object early,
  preventing TypeError when Object.entries receives null or undefined
  (typeof null === "object" in JS, so null slipped through the switch)
- Add test cases covering null/undefined field values, null/undefined
  entries, multiple null fields, and nested null objects (Issue #193)

Co-authored-by: Cursor <cursoragent@cursor.com>
@nadeem-cs nadeem-cs requested a review from a team as a code owner February 12, 2026 10:08
@github-actions
Copy link

github-actions bot commented Feb 12, 2026

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
99.1% (+0.01% 🔼)
659/665
🟢 Branches
91.96% (-0.48% 🔻)
492/535
🟢 Functions 100% 143/143
🟢 Lines
99.35% (+0.01% 🔼)
609/613
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 entry-editable.ts
97.65% (+0.15% 🔼)
91.74% (-1.95% 🔻)
100%
98.65% (+0.1% 🔼)
🟢 gql.ts 100%
90.91% (-9.09% 🔻)
100% 100%

Test suite run success

412 tests passing in 21 suites.

Report generated by 🧪jest coverage report action from 4be5fb6

@github-actions
Copy link

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements
99.1% (+0.01% 🔼)
659/665
🟢 Branches
91.96% (-0.48% 🔻)
492/535
🟢 Functions 100% 143/143
🟢 Lines
99.35% (+0.01% 🔼)
609/613
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢 entry-editable.ts
97.65% (+0.15% 🔼)
91.74% (-1.95% 🔻)
100%
98.65% (+0.1% 🔼)
🟢 gql.ts 100%
90.91% (-9.09% 🔻)
100% 100%

Test suite run success

412 tests passing in 21 suites.

Report generated by 🧪jest coverage report action from 4be5fb6

@nadeem-cs nadeem-cs merged commit e727346 into development Feb 13, 2026
14 checks passed
@nadeem-cs nadeem-cs deleted the fix/DX-3657 branch February 13, 2026 07:43
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.

2 participants