Skip to content

fix(c/driver_manager): preserve quoted-key text in profile redefinition errors#4442

Merged
lidavidm merged 1 commit into
apache:mainfrom
zeroshade:fix-profile-duplicate-quoted-key-msg
Jun 24, 2026
Merged

fix(c/driver_manager): preserve quoted-key text in profile redefinition errors#4442
lidavidm merged 1 commit into
apache:mainfrom
zeroshade:fix-profile-duplicate-quoted-key-msg

Conversation

@zeroshade

Copy link
Copy Markdown
Member

What

A duplicate quoted key in a connection profile (for example, two
"redshift.db_name" entries) produced a confusing parse error that
doubled the first two characters of the key name:

cannot redefine existing string '"reredshift.db_name" '

instead of naming redshift.db_name.

Root cause

The bug is in the vendored toml++ (v3.4.0). parse_string() advances two
characters to detect a """ multi-line delimiter and appends them to the
parser's diagnostics recording_buffer. When the string turns out to be
single-line, go_back(2u) rewinds the read cursor but does not trim those
two characters from recording_buffer, so the lookahead bytes are duplicated
when a redefinition error renders the key via to_sv(recording_buffer). It
only affects quoted keys (the path through the basic/literal string parser);
bare dotted keys are unaffected.

Fix

Backport the upstream fix into both vendored copies
(c/vendor/toml++/toml.hpp and go/adbc/drivermgr/vendored/toml++/toml.hpp).
The fix snapshots recording_buffer.length() before the lookahead and restores
it after go_back(2u).

The fix is not in any tagged toml++ release yet (latest is v3.4.0), so it is
backported here. It re-applies cleanly when the vendored copy is next updated.

Testing

Adds ConnectionProfiles.DuplicateQuotedKey to
c/driver_manager/adbc_driver_manager_test.cc, which writes a profile with a
duplicate quoted key and asserts the resulting error names redshift.db_name
and not the doubled reredshift form. Passes locally
(--gtest_filter=ConnectionProfiles.DuplicateQuotedKey).

…on errors

A duplicate quoted key in a connection profile (e.g. two
"redshift.db_name" entries) produced a parse error that doubled the
first two characters of the key name, reporting 'reredshift.db_name'
instead of 'redshift.db_name'.

The cause is in vendored toml++ (v3.4.0): parse_string() advances two
characters to detect a multi-line delimiter and records them into the
diagnostics recording buffer, but go_back(2u) rewinds the read cursor
without trimming that buffer, so the lookahead characters are
duplicated in redefinition error messages. This only affects quoted
keys.

Backport the upstream fix into both vendored copies (c/vendor and
go/adbc/drivermgr/vendored) and add a regression test exercising a
duplicate quoted key.

Upstream issue: marzer/tomlplusplus#300
Upstream PR:    marzer/tomlplusplus#302
Upstream commit: f22f035fe2d63e2be3d266d8f100e7812a9ab9bd
@zeroshade zeroshade requested a review from lidavidm as a code owner June 24, 2026 15:54
@lidavidm lidavidm merged commit dfe5368 into apache:main Jun 24, 2026
87 checks passed
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.

2 participants