From 0b5edbf44d7c8449e7cfe5f6879e3a09157eba6f Mon Sep 17 00:00:00 2001 From: Iamsohungrynow <261225237+Iamsohungrynow@users.noreply.github.com> Date: Sat, 24 Oct 2026 03:25:55 +0800 Subject: [PATCH] fix(StdConfig): skip top-level values that are not tables --- src/StdConfig.sol | 7 +++++-- test/Config.t.sol | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/StdConfig.sol b/src/StdConfig.sol index 1e632b4e..f66ec6f9 100644 --- a/src/StdConfig.sol +++ b/src/StdConfig.sol @@ -99,8 +99,11 @@ contract StdConfig { // Cache the entire configuration to storage for (uint256 i = 0; i < chain_keys.length; i++) { string memory chain_key = chain_keys[i]; - // Ignore top-level keys that are not tables - if (vm.parseTomlKeys(content, string.concat("$.", chain_key)).length == 0) { + // Ignore top-level keys that are not tables, or are empty tables. + // `parseTomlKeys` reverts for a value that is not a table. + try vm.parseTomlKeys(content, string.concat("$.", chain_key)) returns (string[] memory subKeys) { + if (subKeys.length == 0) continue; + } catch { continue; } uint256 chainId = resolveChainId(chain_key); diff --git a/test/Config.t.sol b/test/Config.t.sol index 553d4321..ad27e999 100644 --- a/test/Config.t.sol +++ b/test/Config.t.sol @@ -456,4 +456,29 @@ contract ConfigTest is Test, Config { vm.removeFile(configOnly); } + + function test_loadConfigIgnoresTopLevelValues() public { + // Only tables are chain sections, so top-level values like these are skipped. + string memory withValues = "./test/fixtures/config_top_level_values.toml"; + vm.writeFile( + withValues, + string.concat( + "version = 1\n", + "owners = [\"0x000000000000000000000000000000000000dEaD\"]\n", + "\n", + "[mainnet]\n", + "endpoint_url = \"https://ethereum.reth.rs/rpc\"\n", + "\n", + "[mainnet.uint]\n", + "number = 1234\n" + ) + ); + + _loadConfig(withValues, false); + + assertEq(config.getChainIds().length, 1); + assertEq(config.get(1, "number").toUint256(), 1234); + + vm.removeFile(withValues); + } }