Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/config/__tests__/toml-loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,20 @@ timezone = "Asia/Seoul"
expect(() => loadTomlConfig()).toThrow('invalid timezone');
});

it('should throw error for non-string timezone (TOML array)', () => {
// ["local"] coerces to the string "local" via RegExp.test(), so the
// typeof guard is required to reject it before it reaches the driver.
const tomlContent = `
[[sources]]
id = "test_db"
dsn = "mysql://user:pass@localhost:3306/testdb"
timezone = ["local"]
`;
fs.writeFileSync(path.join(tempDir, 'dbhub.toml'), tomlContent);

expect(() => loadTomlConfig()).toThrow('invalid timezone');
});

it('should work without timezone (optional field)', () => {
const tomlContent = `
[[sources]]
Expand Down
5 changes: 4 additions & 1 deletion src/config/toml-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ function validateSourceConfig(source: SourceConfig, configPath: string): void {
`Configuration file ${configPath}: source '${source.id}' has 'timezone' but it is only supported for MySQL and MariaDB sources.`
);
}
// Accepted by mysql2/mariadb drivers: "local", "Z", or "±HH:MM" (e.g., "+09:00")
// Accepted by mysql2/mariadb drivers: "local", "Z", or "±HH:MM" (e.g., "+09:00").
// The typeof guard is required: TOML can yield non-strings (e.g. arrays), and
// RegExp.test() would coerce a single-element array like ["local"] to a passing
// string before it reaches the driver as a non-string value.
if (
typeof source.timezone !== "string" ||
!/^(?:local|Z|[+-]\d\d:\d\d)$/.test(source.timezone)
Comment on lines +460 to 466

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Correct — the guard was dropped then restored after the earlier comment, so the net validation diff is now zero (only an explanatory comment + regression test remain). Updated the PR title and description to match: the change set is now the +09:00 test-assertion fix plus the array-case hardening, with no guard removal.

Expand Down
5 changes: 3 additions & 2 deletions src/connectors/__tests__/mysql.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ describe('MySQL Connector Integration Tests', () => {
const connector = new MySQLConnector();
try {
// With timezone "+09:00", the driver reads the naive DATETIME as KST and
// produces the correct UTC instant: 02:31:23 KST == 17:31:23 UTC.
// produces the correct UTC instant. KST is UTC+9, so 02:31:23 on Sep 29
// is 17:31:23 UTC on the previous day (Sep 28).
await connector.connect(mysqlTest.connectionString, undefined, {
timezone: '+09:00',
});
Expand All @@ -419,7 +420,7 @@ describe('MySQL Connector Integration Tests', () => {

expect(result.rows).toHaveLength(1);
const iso = new Date(result.rows[0].dt as string | Date).toISOString();
expect(iso).toBe('2025-09-29T17:31:23.000Z');
expect(iso).toBe('2025-09-28T17:31:23.000Z');
} finally {
await connector.disconnect();
}
Expand Down
Loading