Commit 08fbd1d3 authored by Nick Terrell's avatar Nick Terrell Committed by Facebook Github Bot

Only throw std::invalid_argument on parse error

Summary:
The documentation claims that the constructor only throws
`std::invalid_argument`, but it could throw a `ConversionError`.

Reviewed By: Orvid

Differential Revision: D16387303

fbshipit-source-id: 887a84f48a49acdc0516605f8204432bfd8ca800
parent 8c84783f
......@@ -79,7 +79,12 @@ Uri::Uri(StringPiece str) : hasAuthority_(false), port_(0) {
StringPiece port(authorityMatch[4].first, authorityMatch[4].second);
if (!port.empty()) {
port_ = to<uint16_t>(port);
try {
port_ = to<uint16_t>(port);
} catch (ConversionError const& e) {
throw std::invalid_argument(
to<std::string>("invalid URI port: ", e.what()));
}
}
hasAuthority_ = true;
......
......@@ -408,3 +408,8 @@ TEST(Uri, Simple) {
EXPECT_EQ(s, u.fbstr());
}
}
TEST(Uri, BadPortThrowsInvalidArgument) {
constexpr folly::StringPiece s = "http://localhost:9999999999999999999/";
EXPECT_THROW(Uri{s}, std::invalid_argument);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment