From 0fb562a4d7274aa436cfe0ac96ba72300141a6f3 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Thu, 27 Jul 2017 19:56:15 -0700 Subject: [PATCH] Fix typo in equal_range fix #688 --- CHANGELOG.md | 1 + include/boost/beast/http/impl/fields.ipp | 8 +++++--- test/http/fields.cpp | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 593cd9cc..2c87180c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 90: * Fix websocket read of zero length message +* Fix typo in equal_range -------------------------------------------------------------------------------- diff --git a/include/boost/beast/http/impl/fields.ipp b/include/boost/beast/http/impl/fields.ipp index e3922fd6..f28b19e4 100644 --- a/include/boost/beast/http/impl/fields.ipp +++ b/include/boost/beast/http/impl/fields.ipp @@ -723,11 +723,13 @@ basic_fields:: equal_range(string_view name) const -> std::pair { - auto const result = + auto result = set_.equal_range(name, key_compare{}); + if(result.first == result.second) + return {list_.end(), list_.end()}; return { - list_.iterator_to(result->first), - list_.iterator_to(result->second)}; + list_.iterator_to(*result.first), + ++list_.iterator_to(*(--result.second))}; } //------------------------------------------------------------------------------ diff --git a/test/http/fields.cpp b/test/http/fields.cpp index cec02eec..db6f6c1a 100644 --- a/test/http/fields.cpp +++ b/test/http/fields.cpp @@ -403,6 +403,23 @@ public: BEAST_EXPECT(f.count("dd") == 1); BEAST_EXPECT(f["dd"] == "-"); } + + // equal_range + { + fields f; + f.insert("E", 1); + f.insert("B", 2); + f.insert("D", 3); + f.insert("B", 4); + f.insert("C", 5); + f.insert("B", 6); + f.insert("A", 7); + auto const rng = f.equal_range("B"); + BEAST_EXPECT(std::distance(rng.first, rng.second) == 3); + BEAST_EXPECT(std::next(rng.first, 0)->value() == "2"); + BEAST_EXPECT(std::next(rng.first, 1)->value() == "4"); + BEAST_EXPECT(std::next(rng.first, 2)->value() == "6"); + } } struct sized_body