Trim space in Endpoint::from_string

Fixes: RIPD-1643
This commit is contained in:
Mike Ellery
2018-06-20 17:18:57 -07:00
committed by Nik Bougalis
parent 68bebc472a
commit 8098cba4c2
3 changed files with 28 additions and 2 deletions

View File

@@ -21,6 +21,7 @@
#endif
#include <ripple/beast/net/IPEndpoint.h>
#include <boost/algorithm/string.hpp>
namespace beast {
namespace IP {
@@ -38,7 +39,7 @@ Endpoint::Endpoint (Address const& addr, Port port)
std::pair <Endpoint, bool> Endpoint::from_string_checked (std::string const& s)
{
std::stringstream is (s);
std::stringstream is (boost::trim_copy(s));
Endpoint endpoint;
is >> endpoint;
if (! is.fail() && is.rdbuf()->in_avail() == 0)

View File

@@ -219,6 +219,11 @@ public:
shouldParseEPV4("1.2.3.4", {{1,2,3,4}}, 0);
shouldParseEPV4("1.2.3.4:5", {{1,2,3,4}}, 5);
shouldParseEPV4("1.2.3.4 5", {{1,2,3,4}}, 5, "1.2.3.4:5");
// leading, trailing space
shouldParseEPV4(" 1.2.3.4:5", {{1,2,3,4}}, 5, "1.2.3.4:5");
shouldParseEPV4("1.2.3.4:5 ", {{1,2,3,4}}, 5, "1.2.3.4:5");
shouldParseEPV4("1.2.3.4 ", {{1,2,3,4}}, 0, "1.2.3.4");
shouldParseEPV4(" 1.2.3.4", {{1,2,3,4}}, 0, "1.2.3.4");
shouldParseEPV6(
"2001:db8:a0b:12f0::1",
{{32, 01, 13, 184, 10, 11, 18, 240, 0, 0, 0, 0, 0, 0, 0, 1}},

View File

@@ -20,6 +20,7 @@
#include <ripple/basics/contract.h>
#include <ripple/core/Config.h>
#include <ripple/core/ConfigSections.h>
#include <ripple/server/Port.h>
#include <test/jtx/TestSuite.h>
#include <boost/filesystem.hpp>
#include <boost/format.hpp>
@@ -40,7 +41,7 @@ port_wss_admin
[port_rpc]
port = 5005
ip = 127.0.0.1
admin = 127.0.0.1
admin = 127.0.0.1, ::1
protocol = https
[port_peer]
@@ -852,6 +853,24 @@ trustthesevalidators.gov
}
}
void testPort ()
{
detail::RippledCfgGuard const cfg(*this, "testPort", "", "");
auto const& conf = cfg.config();
if (!BEAST_EXPECT(conf.exists("port_rpc")))
return;
if (!BEAST_EXPECT(conf.exists("port_wss_admin")))
return;
ParsedPort rpc;
if (!unexcept([&]() { parse_Port (rpc, conf["port_rpc"], log); }))
return;
BEAST_EXPECT(rpc.admin_ip && (rpc.admin_ip .get().size() == 2));
ParsedPort wss;
if (!unexcept([&]() { parse_Port (wss, conf["port_wss_admin"], log); }))
return;
BEAST_EXPECT(wss.admin_ip && (wss.admin_ip .get().size() == 1));
}
void run () override
{
testLegacy ();
@@ -860,6 +879,7 @@ trustthesevalidators.gov
testValidatorsFile ();
testSetup (false);
testSetup (true);
testPort ();
}
};