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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[
- **[@rafal-c](https://github.com/rafal-c)** - Added a formatting flag
- **[@jfsimoneau](https://github.com/jfsimoneau)** - Fixed a meson option
- **[@ShereeMorphett](https://github.com/ShereeMorphett)** - Fixed reinterpret_cast usage
- **[@SAY-5](https://github.com/SAY-5)** - Fixed a parser bug
<br>

## Contact
Expand Down
5 changes: 5 additions & 0 deletions include/toml++/impl/parser.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1686,6 +1686,9 @@ TOML_IMPL_NAMESPACE_START
TOML_ASSERT_ASSUME(is_string_delimiter(*cp));
push_parse_scope("string"sv);

// snapshot length so the recording buffer can be rewound alongside go_back(2u) below
const auto recording_buffer_rollback_size = recording_buffer.length();

// get the first three characters to determine the string type
const auto first = cp->value;
advance_and_return_if_error_or_eof({});
Expand Down Expand Up @@ -1716,6 +1719,8 @@ TOML_IMPL_NAMESPACE_START
// step back two characters so that the current
// character is the string delimiter
go_back(2u);
if (recording)
recording_buffer.resize(recording_buffer_rollback_size);

return { first == U'\'' ? parse_literal_string(false) : parse_basic_string(false), false };
}
Expand Down
28 changes: 28 additions & 0 deletions tests/parsing_tables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,34 @@ TEST_CASE("parsing - tables")
});
}

TEST_CASE("parsing - redefinition error messages preserve quoted keys")
{
// https://github.com/marzer/tomlplusplus/issues/300
static constexpr auto src = "[\"foo\"]\nx = 1\n[\"foo\"]\ny = 2\n"sv;
#if TOML_EXCEPTIONS
std::string desc;
bool threw = false;
try
{
[[maybe_unused]] auto res = toml::parse(src);
}
catch (const toml::parse_error& err)
{
threw = true;
desc.assign(err.description());
}
REQUIRE(threw);
CHECK(desc.find("\"foo\"") != std::string::npos);
CHECK(desc.find("fofoo") == std::string::npos);
#else
auto result = toml::parse(src);
REQUIRE(!result);
const std::string desc{ result.error().description() };
CHECK(desc.find("\"foo\"") != std::string::npos);
CHECK(desc.find("fofoo") == std::string::npos);
#endif
}

TEST_CASE("parsing - inline tables")
{
// these are the examples from https://toml.io/en/v1.0.0#inline-table
Expand Down
5 changes: 5 additions & 0 deletions toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14271,6 +14271,9 @@ TOML_IMPL_NAMESPACE_START
TOML_ASSERT_ASSUME(is_string_delimiter(*cp));
push_parse_scope("string"sv);

// snapshot length so the recording buffer can be rewound alongside go_back(2u) below
const auto recording_buffer_rollback_size = recording_buffer.length();

// get the first three characters to determine the string type
const auto first = cp->value;
advance_and_return_if_error_or_eof({});
Expand Down Expand Up @@ -14301,6 +14304,8 @@ TOML_IMPL_NAMESPACE_START
// step back two characters so that the current
// character is the string delimiter
go_back(2u);
if (recording)
recording_buffer.resize(recording_buffer_rollback_size);

return { first == U'\'' ? parse_literal_string(false) : parse_basic_string(false), false };
}
Expand Down
Loading