Skip to content

Commit a2abe94

Browse files
author
Iman
committed
Fix json rendering of large osm ids
1 parent 4ee9968 commit a2abe94

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
- FIXED: Segfault in `UnresolvedManeuverOverride::Turns()` on Australia extracts [#7112](https://github.com/Project-OSRM/osrm-backend/pull/7112)
8787
- 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)
8888
- FIXED: Remove unused C++ headers [#7105](https://github.com/Project-OSRM/osrm-backend/pull/7105)
89+
- FIXED: Fix json rendering problem for large osm ids [#7096](https://github.com/Project-OSRM/osrm-backend/pull/7096)
8990
- Profiles:
9091
- FIXED: Bicycle and foot profiles now don't route on proposed ways [#6615](https://github.com/Project-OSRM/osrm-backend/pull/6615)
9192
- ADDED: Add optional support of cargo bike exclusion and width to bicyle profile [#7044](https://github.com/Project-OSRM/osrm-backend/pull/7044)

include/util/json_renderer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ template <typename Out> struct Renderer
5353
// `fmt::memory_buffer` stores first 500 bytes in the object itself(i.e. on stack in this
5454
// case) and then grows using heap if needed
5555
fmt::memory_buffer buffer;
56-
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{:.10g}"), number.value);
56+
fmt::format_to(std::back_inserter(buffer), FMT_COMPILE("{:.12g}"), number.value);
5757

5858
write(buffer.data(), buffer.size());
5959
}

unit_tests/util/json_render.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ BOOST_AUTO_TEST_CASE(number_truncating)
1212
std::string str;
1313
Renderer<std::string> renderer(str);
1414

15-
// this number would have more than 10 decimals if not truncated
15+
// this number would have more than 12 decimals if not truncated
1616
renderer(Number{42.9995999594999399299});
17-
BOOST_CHECK_EQUAL(str, "42.99959996");
17+
BOOST_CHECK_EQUAL(str, "42.9995999595");
1818
}
1919

2020
BOOST_AUTO_TEST_CASE(integer)
@@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(test_json_issue_6531)
3030
std::string output;
3131
osrm::util::json::Renderer<std::string> renderer(output);
3232
renderer(0.0000000000017114087924596788);
33-
BOOST_CHECK_EQUAL(output, "1.711408792e-12");
33+
BOOST_CHECK_EQUAL(output, "1.71140879246e-12");
3434

3535
output.clear();
3636
renderer(42.0);
@@ -70,23 +70,28 @@ BOOST_AUTO_TEST_CASE(test_json_issue_6531)
7070

7171
output.clear();
7272
renderer(42.123456789);
73-
BOOST_CHECK_EQUAL(output, "42.12345679");
73+
BOOST_CHECK_EQUAL(output, "42.123456789");
7474

7575
output.clear();
7676
renderer(0.12345678912345);
77-
BOOST_CHECK_EQUAL(output, "0.1234567891");
77+
BOOST_CHECK_EQUAL(output, "0.123456789123");
7878

7979
output.clear();
8080
renderer(0.123456789);
8181
BOOST_CHECK_EQUAL(output, "0.123456789");
8282

8383
output.clear();
8484
renderer(0.12345678916);
85-
BOOST_CHECK_EQUAL(output, "0.1234567892");
85+
BOOST_CHECK_EQUAL(output, "0.12345678916");
8686

8787
output.clear();
88-
renderer(123456789123456789.);
89-
BOOST_CHECK_EQUAL(output, "1.234567891e+17");
88+
renderer(12345678912345678.0);
89+
BOOST_CHECK_EQUAL(output, "1.23456789123e+16");
90+
91+
// // handle large osm ids, till 12 digits
92+
output.clear();
93+
renderer(100396615812);
94+
BOOST_CHECK_EQUAL(output, "100396615812");
9095
}
9196

9297
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)