Skip to content

fix: handle undefined variables by returning empty string #820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025

Conversation

chhoumann
Copy link
Owner

@chhoumann chhoumann commented May 29, 2025

Summary

  • Fixed issue where {{VALUE}} and {{VALUE:variableName}} output the literal string "undefined" instead of an empty string
  • Users can now leave template fields empty without seeing "undefined" in their notes

Changes

  • Modified getVariableValue() in completeFormatter.ts to use nullish coalescing operator (??)
  • Added comprehensive test suite to verify the fix and prevent regression

Implementation Details

The fix is a minimal one-line change that addresses the root cause:

// Before
return this.variables.get(variableName) as string;

// After  
return (this.variables.get(variableName) as string) ?? "";

This ensures that null and undefined values are converted to empty strings while preserving all legitimate values including:

  • Empty strings ("")
  • The string "0"
  • The string "false"
  • Any other string value

Test Plan

  • Added unit tests covering all edge cases
  • Tests pass successfully
  • TypeScript compilation succeeds

Related Issues

Fixes #209

🤖 Generated with Claude Code

…'undefined'

- Modified getVariableValue() to use nullish coalescing operator
- Fixes issue where {{VALUE}} outputs "undefined" when no input provided
- Preserves legitimate values like empty strings, "0", and "false"
- Added comprehensive tests to prevent regression

Fixes #209

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

vercel bot commented May 29, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quickadd ✅ Ready (Inspect) Visit Preview May 29, 2025 8:53pm

@chhoumann chhoumann merged commit 6048ef7 into master Jun 18, 2025
2 checks passed
@chhoumann chhoumann deleted the fix/issue-209-undefined-values branch June 18, 2025 18:35
github-actions bot pushed a commit that referenced this pull request Jun 19, 2025
# [1.14.0](1.13.3...1.14.0) (2025-06-19)

### Bug Fixes

* handle undefined variables by returning empty string instead of 'undefined' ([#820](#820)) ([6048ef7](6048ef7)), closes [#209](#209)
* prevent crash when typing comma in VDATE syntax ([2e8939c](2e8939c)), closes [#455](#455)
* replaceLinebreakInString bug with double newlines ([#752](#752)) ([1a02543](1a02543))

### Features

* add canvas template support ([#831](#831)) ([ccfd936](ccfd936)), closes [#663](#663)
* add comma support in VDATE date formats ([6c65266](6c65266))
* add default values for {{VALUE:variable}} syntax ([#821](#821)) ([382294e](382294e)), closes [#569](#569) [#264](#264) [#569](#569)
* **docs:** enhance documentation with improved content, modern design, and framework upgrade ([ae003f8](ae003f8))
* enable VDATE reuse with different formats ([#822](#822)) ([fe1dcac](fe1dcac)), closes [#69](#69)
* enhance field suggestions with advanced filtering and smart defaults ([#826](#826)) ([7b09254](7b09254)), closes [#337](#337) [#337](#337)
Copy link

🎉 This PR is included in version 1.14.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] if no input is provided for {{VALUE}}, output "" instead of "undefined"
1 participant