Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix json rendering of large osm ids #7096

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
- FIXED: Ensure required file check in osrm-routed is correctly enforced. [#6655](https://github.com/Project-OSRM/osrm-backend/pull/6655)
- FIXED: Correct HTTP docs to reflect summary output dependency on steps parameter. [#6655](https://github.com/Project-OSRM/osrm-backend/pull/6655)
- ADDED: Extract prerelease/build information from package semver [#6839](https://github.com/Project-OSRM/osrm-backend/pull/6839)
- FIXED: Fix json rendering problem for large osm ids [#7096](https://github.com/Project-OSRM/osrm-backend/pull/7096)
- FIXED: Segfault in `UnresolvedManeuverOverride::Turns()` on Australia extracts [#7112](https://github.com/Project-OSRM/osrm-backend/pull/7112)
- CHANGED: Replaced PL:trunk with PL:expressway to match the latest changes in Polish tagging [#7079](https://github.com/Project-OSRM/osrm-backend/pull/7079)
- FIXED: Remove unused C++ headers [#7105](https://github.com/Project-OSRM/osrm-backend/pull/7105)
Expand Down
7 changes: 6 additions & 1 deletion include/util/json_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ template <typename Out> struct Renderer
// `fmt::memory_buffer` stores first 500 bytes in the object itself(i.e. on stack in this
// case) and then grows using heap if needed
fmt::memory_buffer buffer;
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{:.10g}"), number.value);
if (static_cast<std::uint64_t>(number.value) == number.value)
fmt::format_to(std::back_inserter(buffer),
FMT_COMPILE("{}"),
static_cast<std::uint64_t>(number.value));
else
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{:.10g}"), number.value);

write(buffer.data(), buffer.size());
}
Expand Down
9 changes: 7 additions & 2 deletions unit_tests/util/json_render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ BOOST_AUTO_TEST_CASE(test_json_issue_6531)
BOOST_CHECK_EQUAL(output, "0.1234567892");

output.clear();
renderer(123456789123456789.);
BOOST_CHECK_EQUAL(output, "1.234567891e+17");
renderer(12345678912345678.);
BOOST_CHECK_EQUAL(output, "12345678912345678");

// handle large osm ids
output.clear();
renderer(1000396615812);
BOOST_CHECK_EQUAL(output, "1000396615812");
}

BOOST_AUTO_TEST_SUITE_END()
Loading