Skip to content

fix: correct semicolon handling in parse() and quoting in build() - #299

Merged
dhensby merged 4 commits into
tediousjs:masterfrom
dhensby:claude/issue-298-994b66
Nov 18, 2026
Merged

dhensby merged 4 commits into
tediousjs:masterfrom
dhensby:claude/issue-298-994b66

Conversation

@dhensby

@dhensby dhensby commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

This PR fixes the parser and builder problems reported in #298. It also covers item 1 of #279, because the cause is in the same part of the parser.

Changes

  • parse() skips repeated semicolons between pairs. Before, ;; in an unquoted value was read as an escaped ;, so Server=h;;Database=d gave server the value h;Database=d. A leading ; also stayed in the first key. Now ; always ends an unquoted value, and whitespace and extra ; before a key are skipped, as in SqlClient. Doubling is still an escape for = in keys (==) and for closing quotes inside quoted values.
  • parse() checks the first character of a key or value. Before, the first character skipped the terminator checks. So Key=;Encrypt=true gave key the value ;Encrypt=true, and ==Key=Value gave the key =. An empty value is now '', and a key can start with ==. An empty key, for example in =Value, now throws Malformed connection string, as SqlClient does. Before, that pair was dropped, or joined with the next pair.
  • build() quotes values with leading or trailing whitespace, or with a leading ' or ". These values now round-trip through parse(). For example, build({ Password: ' secret ' }) gives Password={ secret }.
  • build() escapes = in keys as ==. For example, build({ 'a=b': '1' }) gives a==b=1, which parses back to the key a=b.

Behaviour changes

These changes follow the SqlClient syntax that the README links to, but they can change results for existing input:

  • ;; in an unquoted value no longer gives a literal ;. A value that contains ; must be quoted, for example Password={a;b}.
  • parse() now throws on an empty key.
  • build() now keeps the quotes on a value that is already wrapped in '...' or "...". For example, build({ Authentication: '"Active Directory Default"' }) gives Authentication={"Active Directory Default"}, which parses back with the quotes.

Not in this PR

Testing

  • Each change has new fixtures or tests that fail on master and pass on this branch.
  • npm run lint, npm run test:coverage and npm run build pass on each commit. The tests pass on Node 20, 22 and 24.
  • I compared parse() with a port of SqlClient's DbConnectionOptions.GetKeyValuePair for every string up to 7 characters over two small alphabets of separators, quotes and letters (7.8 million strings). There are no differences, apart from three known ones: this library accepts {} quotes, accepts an unquoted value that ends in a quote, and drops a last key that has no =. The same check on master gives 126,744 differences for strings up to 6 characters.
  • A build-then-parse round-trip fuzz found no failures, apart from the {a} case in Parser swallows the pair after an empty value; builder mis-quotes brace-wrapped values and a bare ( #279 and keys that the syntax can't represent.

Closes #298

🤖 Generated with Claude Code

dhensby and others added 4 commits November 18, 2026 15:48
A `;;` in an unquoted value was read as an escaped `;`. So
`Server=h;;Database=d` gave `server` the value `h;Database=d`, and the
`Database` pair was lost. A `;` at the start of a key stayed in the key,
so `;Server=h` gave the key `;server`.

In the SqlClient connection string syntax, `;` separates pairs and
extra semicolons before or between pairs are skipped. A value that
contains `;` must be quoted. Outside a quoted value, doubling only
escapes `=` in a key (`==`). The parser now ends an unquoted value at
the first `;`, and skips whitespace and `;` before a key.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parser added the first character of a key or value to the buffer
without checking if it was a terminator. So `Key=;Encrypt=true` gave
`key` the value `;Encrypt=true`, and the `Encrypt` pair was lost. A key
that starts with an escaped `=` was also misread: `==Key=Value` gave
the key `=` with the value `Key=Value`.

The first character now goes through the same checks as the others.
An empty value is now collected as an empty string. An empty key, for
example in `=Value`, now throws "Malformed connection string", as
SqlClient does. Before, the parser silently dropped such a pair, or
joined it with the next pair when one followed (`=Value;Next=x` gave
the key `=value;next`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uote

`build()` wrote these values without quotes, so `parse()` did not read
them back correctly. The parser trims unquoted values, so ` secret `
came back as `secret`. The parser also reads a leading `'` or `"` as an
opening quote. So `'abc` threw "Connection string terminated
unexpectedly", and `"x"` came back as `x`.

`build()` now wraps these values in `{...}`, as it does for values that
contain other special characters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`build()` wrote a key that contains `=` as it was, and `parse()` ended
the key at the first `=`. For example, `build({ 'a=b': '1' })` gave
`a=b=1`, which parsed as the key `a` with the value `b=1`.

`build()` now writes each `=` in a key as `==`. The parser reads `==`
in a key as a literal `=`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Core parse()/build() behavior changes would automatically reach node-mssql consumers on ^1.0.0, requiring maintainers to confirm whether a patch release is semver-compatible.

No open issues 🎉

What changed in this PR

Corrects connection-string parsing and serialization to address #298 and the empty-value issue in #279.

Changes:

  • Fixes repeated semicolons, empty values, and escaped = characters in keys; rejects empty keys.
  • Preserves whitespace and leading quotes in built values, and escapes = in keys.
  • Adds parser regression cases and builder round-trip tests.
File Description
test/​parser/​fixture/​connection-strings.json Adds separator, empty-value, and escaped-key fixtures.
test/​parser/​connection-string.test.ts Tests rejection of empty keys.
test/​builder/​builder.test.ts Tests value quoting, key escaping, and round trips.
src/​parser/​connection-string-parser.ts Corrects separator and first-character handling.
src/​builder/​index.ts Quotes sensitive values and escapes = in keys.

Review effort: Max

@dhensby
dhensby marked this pull request as ready for review November 18, 2026 16:23
@dhensby
dhensby merged commit 00e6206 into tediousjs:master Nov 18, 2026
7 checks passed
@dhensby
dhensby deleted the claude/issue-298-994b66 branch November 18, 2026 16:23
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.1.1 🎉

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.

;; is read as an escaped semicolon in values, and build() does not quote leading/trailing spaces, leading quotes, or = in keys

2 participants