Skip to content

Fix falsy string values like "0" being treated as empty#7

Open
ritterg wants to merge 1 commit intomasterfrom
fix/falsy-string-values
Open

Fix falsy string values like "0" being treated as empty#7
ritterg wants to merge 1 commit intomasterfrom
fix/falsy-string-values

Conversation

@ritterg
Copy link
Copy Markdown
Collaborator

@ritterg ritterg commented Mar 26, 2026

Summary

  • getValueAsString() used ?: (falsy check) instead of ?? (null coalescing), causing the string "0" to return $default (null) instead of "0"
  • hasValue() used !empty($value) which also treats "0" as empty in PHP, causing getValue() to return the default as well
  • Both methods now correctly handle all non-null values including falsy strings

Test plan

  • Added test test_falsy_string_values that creates a setting with value "0" and asserts hasValue(), setting(), settingAsString(), and getValueAsString() all return the correct value
  • All 27 tests pass

🤖 Generated with Claude Code

getValueAsString() used ?: (falsy check) instead of ?? (null coalescing),
causing string "0" to return the default value. hasValue() used !empty()
which also treats "0" as empty. Both now correctly handle all non-null values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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