Skip to content

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

Closed

Description

@trackoor

parse() treats ;; inside an unquoted value as an escaped semicolon (swallowing the following key/value pair) and keeps a leading ; on the first key, while build() does not quote values with leading/trailing whitespace or a leading '/" and does not escape = in keys (separate from #279, which covers empty values, {...} values, and bare ().

// repro.cjs
const { parse, build } = require("@tediousjs/connection-string");
const show = s => console.log(JSON.stringify(s), "->", JSON.stringify(Object.fromEntries(parse(s))));
show("Server=h;;Database=d;User Id=u");
show(";Server=h");
for (const v of [" secret ", "'abc", "\"x\""]) {
  const s = build({ Password: v });
  let back; try { back = parse(s).get("password"); } catch (e) { back = "throws: " + e.message; }
  console.log(JSON.stringify(v), "->", JSON.stringify(s), "->", JSON.stringify(back));
}
console.log(JSON.stringify(build({ "a=b": "1" })), "->", JSON.stringify(Object.fromEntries(parse(build({ "a=b": "1" })))));
npm i @tediousjs/connection-string@1.1.0
node repro.cjs

Actual:

"Server=h;;Database=d;User Id=u" -> {"server":"h;Database=d","user id":"u"}
";Server=h" -> {";server":"h"}
" secret " -> "Password= secret " -> "secret"
"'abc" -> "Password='abc" -> "throws: Connection string terminated unexpectedly"
"\"x\"" -> "Password=\"x\"" -> "x"
"a=b=1" -> {"a":"b=1"}

Expected:

  1. parse("Server=h;;Database=d;User Id=u") returns {"server":"h","database":"d","user id":"u"}, and parse(";Server=h") returns {"server":"h"}. Per the SqlConnection.ConnectionString syntax linked in the README, ; separates pairs (extra semicolons before or between pairs are skipped) and a ; inside a value requires quotes; doubling only escapes = in keywords (==) and closing quotes inside quoted values.
  2. build({ Password: v }) quotes values with leading/trailing whitespace or a leading ' or " (for example wrapping in {...} with } doubled), so parse(build({ Password: v })).get("password") returns " secret ", "'abc", and "\"x\"".
  3. build({ "a=b": "1" }) writes "a==b=1", which parse() reads back as {"a=b":"1"}.

In src/parser/connection-string-parser.ts, the unquoted isTerminator branch doubles terminator in value mode as well as key mode (and !started in key mode does not skip ;), while needsQuotes and encodeTuple in src/builder/index.ts do not check for leading/trailing whitespace, leading '/", or = in keys.

Version: @tediousjs/connection-string 1.1.0 and master (76a5db3), Node.js v26.13.0.

Credit: https://ucsbplse.github.io/

Activity

  1. dhensby commented on Nov 18, 2026

    @dhensby
    Collaborator

    Thanks for the report. This has been fixed in #299

  2. github-actions commented on Nov 18, 2026

    @github-actions

    🎉 This issue has been resolved 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions