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 a case where ripple::Expected returned a json array, not a value #4401

Merged
merged 1 commit into from
Mar 24, 2023
Merged
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
6 changes: 3 additions & 3 deletions src/ripple/basics/Expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ class [[nodiscard]] Expected
public:
template <typename U>
requires std::convertible_to<U, T> constexpr Expected(U && r)
: Base(T{std::forward<U>(r)})
: Base(T(std::forward<U>(r)))
{
}

template <typename U>
requires std::convertible_to<U, E> &&
(!std::is_reference_v<U>)constexpr Expected(Unexpected<U> e)
: Base(E{std::move(e.value())})
: Base(E(std::move(e.value())))
{
}

Expand Down Expand Up @@ -220,7 +220,7 @@ class [[nodiscard]] Expected<void, E>
template <typename U>
requires std::convertible_to<U, E> &&
(!std::is_reference_v<U>)constexpr Expected(Unexpected<U> e)
: Base(E{std::move(e.value())})
: Base(E(std::move(e.value())))
{
}

Expand Down
13 changes: 13 additions & 0 deletions src/test/basics/Expected_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include <ripple/basics/Expected.h>
#include <ripple/beast/unit_test.h>
#include <ripple/protocol/TER.h>
#if BOOST_VERSION >= 107500
#include <boost/json.hpp> // Not part of boost before version 1.75
#endif // BOOST_VERSION
#include <array>
#include <cstdint>

Expand Down Expand Up @@ -203,6 +206,16 @@ struct Expected_test : beast::unit_test::suite
std::string const s(std::move(expected.error()));
BEAST_EXPECT(s == "Not what is expected!");
}
// Test a case that previously unintentionally returned an array.
#if BOOST_VERSION >= 107500
{
auto expected = []() -> Expected<boost::json::value, std::string> {
return boost::json::object{{"oops", "me array now"}};
}();
BEAST_EXPECT(expected);
BEAST_EXPECT(!expected.value().is_array());
}
#endif // BOOST_VERSION
}
};

Expand Down