Skip to content

Commit e5df0c4

Browse files
author
Iman
committed
Fix json rendering of large osm ids
1 parent 3614af7 commit e5df0c4

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

include/util/json_renderer.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,10 @@ template <typename Out> struct Renderer
5454
// `fmt::memory_buffer` stores first 500 bytes in the object itself(i.e. on stack in this
5555
// case) and then grows using heap if needed
5656
fmt::memory_buffer buffer;
57-
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{:.10g}"), number.value);
57+
if (static_cast<std::uint64_t>(number.value) == number.value)
58+
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{}"), static_cast<std::uint64_t>(number.value));
59+
else
60+
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{:.10g}"), number.value);
5861

5962
write(buffer.data(), buffer.size());
6063
}

unit_tests/util/json_render.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,13 @@ BOOST_AUTO_TEST_CASE(test_json_issue_6531)
8787
BOOST_CHECK_EQUAL(output, "0.1234567892");
8888

8989
output.clear();
90-
renderer(123456789123456789.);
91-
BOOST_CHECK_EQUAL(output, "1.234567891e+17");
90+
renderer(12345678912345678.);
91+
BOOST_CHECK_EQUAL(output, "12345678912345678");
92+
93+
// handle large osm ids
94+
output.clear();
95+
renderer(1000396615812);
96+
BOOST_CHECK_EQUAL(output, "1000396615812");
9297
}
9398

9499
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)