Skip to content

Commit dfe5368

Browse files
authored
fix(c/driver_manager): preserve quoted-key text in profile redefinition errors (#4442)
marzer/tomlplusplus@f22f035
1 parent 05995bb commit dfe5368

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

c/driver_manager/adbc_driver_manager_test.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,34 @@ TEST_F(ConnectionProfiles, DotSeparatedKey) {
17311731
UnsetProfilePath();
17321732
}
17331733

1734+
TEST_F(ConnectionProfiles, DuplicateQuotedKey) {
1735+
// Regression: a duplicate *quoted* key must report the real key name, not a
1736+
// copy with its first two characters doubled (vendored toml++ bug, fixed
1737+
// upstream in marzer/tomlplusplus#300 / PR #302 / commit f22f035).
1738+
auto filepath = temp_dir / "profile.toml";
1739+
std::ofstream test_profile_file(filepath);
1740+
ASSERT_TRUE(test_profile_file.is_open());
1741+
test_profile_file << "profile_version = 1\n"
1742+
"driver = \"adbc_driver_sqlite\"\n"
1743+
"[Options]\n"
1744+
"\"redshift.db_name\" = \"dev\"\n"
1745+
"\"redshift.db_name\" = \"sample_datadev\"\n";
1746+
test_profile_file.close();
1747+
1748+
adbc_validation::Handle<struct AdbcDatabase> database;
1749+
1750+
// find profile by name using ADBC_PROFILE_PATH
1751+
SetProfilePath(temp_dir.string().c_str());
1752+
ASSERT_THAT(AdbcDatabaseNew(&database.value, &error), IsOkStatus(&error));
1753+
ASSERT_THAT(AdbcDatabaseSetOption(&database.value, "profile", "profile", &error),
1754+
IsOkStatus(&error));
1755+
ASSERT_THAT(AdbcDatabaseInit(&database.value, &error),
1756+
IsStatus(ADBC_STATUS_INVALID_ARGUMENT, &error));
1757+
ASSERT_THAT(error.message, ::testing::HasSubstr("redshift.db_name"));
1758+
ASSERT_THAT(error.message, ::testing::Not(::testing::HasSubstr("reredshift")));
1759+
UnsetProfilePath();
1760+
}
1761+
17341762
TEST_F(ConnectionProfiles, UseEnvVar) {
17351763
auto filepath = temp_dir / "profile.toml";
17361764
toml::table profile = toml::parse(R"|(

c/vendor/toml++/toml.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14130,6 +14130,9 @@ TOML_IMPL_NAMESPACE_START
1413014130
TOML_ASSERT_ASSUME(is_string_delimiter(*cp));
1413114131
push_parse_scope("string"sv);
1413214132

14133+
// snapshot length so the recording buffer can be rewound alongside go_back(2u) below
14134+
const auto recording_buffer_rollback_size = recording_buffer.length();
14135+
1413314136
// get the first three characters to determine the string type
1413414137
const auto first = cp->value;
1413514138
advance_and_return_if_error_or_eof({});
@@ -14160,6 +14163,8 @@ TOML_IMPL_NAMESPACE_START
1416014163
// step back two characters so that the current
1416114164
// character is the string delimiter
1416214165
go_back(2u);
14166+
if (recording)
14167+
recording_buffer.resize(recording_buffer_rollback_size);
1416314168

1416414169
return { first == U'\'' ? parse_literal_string(false) : parse_basic_string(false), false };
1416514170
}

go/adbc/drivermgr/vendored/toml++/toml.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14130,6 +14130,9 @@ TOML_IMPL_NAMESPACE_START
1413014130
TOML_ASSERT_ASSUME(is_string_delimiter(*cp));
1413114131
push_parse_scope("string"sv);
1413214132

14133+
// snapshot length so the recording buffer can be rewound alongside go_back(2u) below
14134+
const auto recording_buffer_rollback_size = recording_buffer.length();
14135+
1413314136
// get the first three characters to determine the string type
1413414137
const auto first = cp->value;
1413514138
advance_and_return_if_error_or_eof({});
@@ -14160,6 +14163,8 @@ TOML_IMPL_NAMESPACE_START
1416014163
// step back two characters so that the current
1416114164
// character is the string delimiter
1416214165
go_back(2u);
14166+
if (recording)
14167+
recording_buffer.resize(recording_buffer_rollback_size);
1416314168

1416414169
return { first == U'\'' ? parse_literal_string(false) : parse_basic_string(false), false };
1416514170
}

0 commit comments

Comments
 (0)