From c7e48b5598151c415123adfa8e7374516c49ea49 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 23 Jul 2022 13:29:45 +0200 Subject: [PATCH 1/3] Fix bug with reading Set values from Lua scripts. --- CHANGELOG.md | 1 + features/foot/restrictions.feature | 4 ++-- src/extractor/scripting_environment_lua.cpp | 24 +++++++++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 060e2c77f95..c089f74da43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - API: - FIXED: Fix inefficient osrm-routed connection handling [#6113](https://github.com/Project-OSRM/osrm-backend/pull/6113) - Build: + - CHANGED: Fix bug with reading Set values from Lua scripts. [#6285](https://github.com/Project-OSRM/osrm-backend/pull/6285) - CHANGED: Enable even more clang-tidy checks. [#6273](https://github.com/Project-OSRM/osrm-backend/pull/6273) - CHANGED: Configure CMake to not build flatbuffers tests and samples. [#6274](https://github.com/Project-OSRM/osrm-backend/pull/6274) - CHANGED: Enable more clang-tidy checks. [#6270](https://github.com/Project-OSRM/osrm-backend/pull/6270) diff --git a/features/foot/restrictions.feature b/features/foot/restrictions.feature index 5273a47b116..263aa6416c6 100644 --- a/features/foot/restrictions.feature +++ b/features/foot/restrictions.feature @@ -29,7 +29,7 @@ Feature: Foot - Turn restrictions When I route I should get | from | to | route | | s | w | sj,wj,wj | - | s | n | sj,nj,nj | + | s | n | sj,nj | | s | e | sj,ej,ej | @only_turning @@ -55,7 +55,7 @@ Feature: Foot - Turn restrictions When I route I should get | from | to | route | | s | w | sj,wj,wj | - | s | n | sj,nj,nj | + | s | n | sj,nj | | s | e | sj,ej,ej | @except diff --git a/src/extractor/scripting_environment_lua.cpp b/src/extractor/scripting_environment_lua.cpp index 182dd792915..c0716071d3f 100644 --- a/src/extractor/scripting_environment_lua.cpp +++ b/src/extractor/scripting_environment_lua.cpp @@ -939,6 +939,26 @@ Sol2ScriptingEnvironment::GetStringListFromFunction(const std::string &function_ return strings; } +namespace +{ + +// string list can be defined either as a Set(see profiles/lua/set.lua) or as a Sequence (see +// profiles/lua/sequence.lua) `Set` is a table with keys that are actual values we are looking for +// and values that always `true`. `Sequence` is a table with keys that are indices and values that +// are actual values we are looking for. + +std::string GetSetOrSequenceValue(const std::pair &pair) +{ + if (pair.second.is()) + { + return pair.second.as(); + } + BOOST_ASSERT(pair.first.is()); + return pair.first.as(); +} + +} // namespace + std::vector Sol2ScriptingEnvironment::GetStringListFromTable(const std::string &table_name) { @@ -954,7 +974,7 @@ Sol2ScriptingEnvironment::GetStringListFromTable(const std::string &table_name) { for (auto &&pair : table) { - strings.push_back(pair.second.as()); + strings.emplace_back(GetSetOrSequenceValue(pair)); } } return strings; @@ -989,7 +1009,7 @@ Sol2ScriptingEnvironment::GetStringListsFromTable(const std::string &table_name) std::vector inner_vector; for (const auto &inner_pair : inner_table) { - inner_vector.push_back(inner_pair.first.as()); + inner_vector.emplace_back(GetSetOrSequenceValue(inner_pair)); } string_lists.push_back(std::move(inner_vector)); } From 77d82062bb3f9f52a5618543fd927e35d9203e35 Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Sat, 23 Jul 2022 13:46:01 +0200 Subject: [PATCH 2/3] Fix bug with reading Set values from Lua scripts. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c089f74da43..2d49ef7117d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,9 @@ - Changes from 5.26.0 - API: - FIXED: Fix inefficient osrm-routed connection handling [#6113](https://github.com/Project-OSRM/osrm-backend/pull/6113) + - Misc: + - FIXED: Fix bug with reading Set values from Lua scripts. [#6285](https://github.com/Project-OSRM/osrm-backend/pull/6285) - Build: - - CHANGED: Fix bug with reading Set values from Lua scripts. [#6285](https://github.com/Project-OSRM/osrm-backend/pull/6285) - CHANGED: Enable even more clang-tidy checks. [#6273](https://github.com/Project-OSRM/osrm-backend/pull/6273) - CHANGED: Configure CMake to not build flatbuffers tests and samples. [#6274](https://github.com/Project-OSRM/osrm-backend/pull/6274) - CHANGED: Enable more clang-tidy checks. [#6270](https://github.com/Project-OSRM/osrm-backend/pull/6270) From 2927e59fedf4baf6a1e7eccb5253c56665d7ad24 Mon Sep 17 00:00:00 2001 From: Michael Bell Date: Sat, 30 Jul 2022 21:03:26 +0100 Subject: [PATCH 3/3] Add test for foot profile named-road suffixes --- features/foot/names.feature | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/features/foot/names.feature b/features/foot/names.feature index c14b00b7f46..8b8498c2622 100644 --- a/features/foot/names.feature +++ b/features/foot/names.feature @@ -20,3 +20,20 @@ Feature: Foot - Street names in instructions When I route I should get | from | to | route | ref | | a | c | My Way,, | ,A7,A7 | + + + Scenario: Foot - Combines named roads with suffix changes + Given the node map + """ + a b c d + """ + + And the ways + | nodes | name | + | ab | High Street W | + | bc | High Street E | + | cd | Market Street | + + When I route I should get + | from | to | route | + | a | d | High Street W,Market Street,Market Street |