mirror of
https://github.com/nlohmann/json.git
synced 2026-11-05 12:19:21 +00:00
🐛 fix bug in diagnostics_t
This commit is contained in:
3 files changed
+10
-4
No files matched your search
@@ -36,7 +36,7 @@ class diagnostics_t
|
|||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
|
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
|
||||||
{
|
{
|
||||||
if (current->m_parent->m_value.array->operator[](i) == *current)
|
if (¤t->m_parent->m_value.array->operator[](i) == current)
|
||||||
{
|
{
|
||||||
tokens.emplace_back(std::to_string(i));
|
tokens.emplace_back(std::to_string(i));
|
||||||
break;
|
break;
|
||||||
@@ -49,7 +49,7 @@ class diagnostics_t
|
|||||||
{
|
{
|
||||||
for (const auto& element : *current->m_parent->m_value.object)
|
for (const auto& element : *current->m_parent->m_value.object)
|
||||||
{
|
{
|
||||||
if (element.second == *current)
|
if (&element.second == current)
|
||||||
{
|
{
|
||||||
tokens.emplace_back(element.first.c_str());
|
tokens.emplace_back(element.first.c_str());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -2534,7 +2534,7 @@ class diagnostics_t
|
|||||||
{
|
{
|
||||||
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
|
for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i)
|
||||||
{
|
{
|
||||||
if (current->m_parent->m_value.array->operator[](i) == *current)
|
if (¤t->m_parent->m_value.array->operator[](i) == current)
|
||||||
{
|
{
|
||||||
tokens.emplace_back(std::to_string(i));
|
tokens.emplace_back(std::to_string(i));
|
||||||
break;
|
break;
|
||||||
@@ -2547,7 +2547,7 @@ class diagnostics_t
|
|||||||
{
|
{
|
||||||
for (const auto& element : *current->m_parent->m_value.object)
|
for (const auto& element : *current->m_parent->m_value.object)
|
||||||
{
|
{
|
||||||
if (element.second == *current)
|
if (&element.second == current)
|
||||||
{
|
{
|
||||||
tokens.emplace_back(element.first.c_str());
|
tokens.emplace_back(element.first.c_str());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -95,4 +95,10 @@ TEST_CASE("Better diagnostics")
|
|||||||
{
|
{
|
||||||
CHECK_THROWS_WITH_AS(json::parse(""), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error);
|
CHECK_THROWS_WITH_AS(json::parse(""), "[json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected end of input; expected '[', '{', or a literal", json::parse_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("Regression test for https://github.com/nlohmann/json/pull/2562#pullrequestreview-574858448")
|
||||||
|
{
|
||||||
|
CHECK_THROWS_WITH_AS(json({"0", "0"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
|
||||||
|
CHECK_THROWS_WITH_AS(json({"0", "1"})[1].get<int>(), "[json.exception.type_error.302] (/1) type must be number, but is string", json::type_error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user