Skip to content

fix: trim a value before boolean coercion - #301

Merged
dhensby merged 1 commit into
tediousjs:masterfrom
dhensby:fix/trim-boolean-values
Nov 19, 2026
Merged

dhensby merged 1 commit into
tediousjs:masterfrom
dhensby:fix/trim-boolean-values

Conversation

@dhensby

@dhensby dhensby commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

get(key, 'boolean') now trims a value before it compares it with false, no and 0. Before, a quoted value with surrounding whitespace, such as TrustServerCertificate={ no } or Encrypt=" false ", gave true.

Changes

  • Boolean coercion trims the value first. SqlClient also trims the value of its boolean keywords, such as TrustServerCertificate.
  • A quoted value of only whitespace now gives false in get(), as an empty value does. toSchema() already gives the schema default for such a value, so its result does not change.
  • The README states the coercion rules for get().

Values that are not recognised, such as off, still give true. That needs a separate decision.

Behaviour changes

Only quoted values with surrounding whitespace change, and they only change from true to false:

  • TrustServerCertificate={ no } now gives false, so the certificate is validated.
  • Encrypt=" false " now gives false, which is what the value says.

Values without surrounding whitespace do not change.

Testing

  • The new unit test and fixture fail on 1.1.2 and pass on this branch.
  • npm run lint, npm run test:coverage, npm run build and tsc --noEmit pass. All 70 tests pass on Node 20, 22 and 24.
  • I compared 1.1.2 and this branch over 1.3 million generated inputs, quoted and unquoted, with several kinds of whitespace. Every difference is a quoted value that trims to false, no, 0 or nothing, and every difference goes from true to false.

Part of #279.

🤖 Generated with Claude Code

The parser keeps the surrounding whitespace of a quoted value. Boolean
coercion then compared the value with `false`, `no` and `0` without
trimming it. So `TrustServerCertificate={ no }` and
`Encrypt=" false "` gave true.

Boolean coercion now trims the value first. SqlClient also trims the
value of its boolean keywords, such as TrustServerCertificate. A quoted
value of only whitespace now gives false, as an empty value does.
Values that are not recognised still give true.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhensby
dhensby marked this pull request as ready for review November 19, 2026 14:45
@dhensby
dhensby merged commit 29bfe61 into tediousjs:master Nov 19, 2026
7 checks passed
@dhensby
dhensby deleted the fix/trim-boolean-values branch November 19, 2026 14:45
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.1.3 🎉

The release is available on:

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.

1 participant