Skip to content

Parser swallows the pair after an empty value; builder mis-quotes brace-wrapped values and a bare ( #279

Description

@dhensby

Found while reviewing how node-mssql consumes this package (1.1.0; the same code is on master).

1. An empty unquoted value absorbs the next Key=Value pair.

parse('TrustServerCertificate=;Encrypt=true;Server=h') gives { trustservercertificate: ';Encrypt=true', server: 'h' }. The Encrypt key is lost and the empty value becomes ;Encrypt=true. The quoted form TrustServerCertificate="";Encrypt=true;Server=h parses correctly, so this is specific to the unstarted/unquoted branch (connection-string-parser.ts: the !started path pushes the first non-whitespace character without checking isTerminator). Templates rendered with an unset variable hit this.

Expected: { trustservercertificate: '', encrypt: 'true', server: 'h' }.

2. build() treats a value that starts with { and ends with } as already quoted.

build({ Pwd: '{a}' }) gives Pwd={a}, and parse() of that gives a, so a literal value {a} cannot round-trip. Expected Pwd={{a}}}, or an explicit per-key way to pass a pre-quoted value such as Driver={ODBC Driver 18 for SQL Server}, which is presumably what the heuristic exists for.

3. needsQuotes misses a bare (.

The regex alternative \|\( matches the two-character sequence |(, not (: build({ Pwd: 'a(b' }) gives Pwd=a(b while build({ Pwd: 'a|(b' }) is quoted. Also, } inside a quoted value is emitted as }}, which is the SqlClient convention; the ODBC SQLDriverConnect grammar does not define an escape for } inside braces, so it may be worth documenting which dialect build() targets.

4. Unknown boolean values coerce to true.

The schema coerces anything outside false/no/0 to true, so TrustServerCertificate=off or a typo becomes true, and Encrypt=strict loses its meaning. ADO.NET's SqlConnectionStringBuilder and the ODBC driver reject unrecognised boolean values; consider throwing, or keeping the raw string for keys that accept more than two values.

Happy to send PRs for 1 to 3 if that helps.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions