diff --git a/ntcore/src/main/native/cpp/Dispatcher.cpp b/ntcore/src/main/native/cpp/Dispatcher.cpp index f43bd15ecd..ea54fe4042 100644 --- a/ntcore/src/main/native/cpp/Dispatcher.cpp +++ b/ntcore/src/main/native/cpp/Dispatcher.cpp @@ -22,14 +22,15 @@ using namespace nt; void Dispatcher::StartServer(const Twine& persist_filename, const char* listen_address, unsigned int port) { + std::string listen_address_copy(StringRef(listen_address).trim()); DispatcherBase::StartServer( persist_filename, std::unique_ptr(new wpi::TCPAcceptor( - static_cast(port), listen_address, m_logger))); + static_cast(port), listen_address_copy.c_str(), m_logger))); } void Dispatcher::SetServer(const char* server_name, unsigned int port) { - std::string server_name_copy(server_name); + std::string server_name_copy(StringRef(server_name).trim()); SetConnector([=]() -> std::unique_ptr { return wpi::TCPConnector::connect(server_name_copy.c_str(), static_cast(port), m_logger, 1); @@ -40,7 +41,7 @@ void Dispatcher::SetServer( ArrayRef> servers) { wpi::SmallVector, 16> servers_copy; for (const auto& server : servers) - servers_copy.emplace_back(std::string{server.first}, + servers_copy.emplace_back(std::string{server.first.trim()}, static_cast(server.second)); SetConnector([=]() -> std::unique_ptr { @@ -94,7 +95,7 @@ void Dispatcher::SetServerTeam(unsigned int team, unsigned int port) { } void Dispatcher::SetServerOverride(const char* server_name, unsigned int port) { - std::string server_name_copy(server_name); + std::string server_name_copy(StringRef(server_name).trim()); SetConnectorOverride([=]() -> std::unique_ptr { return wpi::TCPConnector::connect(server_name_copy.c_str(), static_cast(port), m_logger, 1); diff --git a/ntcore/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java b/ntcore/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java index 7035146b2b..9628a0e411 100644 --- a/ntcore/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java +++ b/ntcore/src/test/java/edu/wpi/first/networktables/ConnectionListenerTest.java @@ -15,6 +15,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.DisabledOnOs; import org.junit.jupiter.api.condition.OS; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -112,16 +114,17 @@ class ConnectionListenerTest { } - @Test + @ParameterizedTest @DisabledOnOs(OS.WINDOWS) @SuppressWarnings("PMD.AvoidUsingHardCodedIP") - void testThreaded() { - m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000); + @ValueSource(strings = { "127.0.0.1", "127.0.0.1 ", " 127.0.0.1 " }) + void testThreaded(String address) { + m_serverInst.startServer("connectionlistenertest.ini", address, 10000); List events = new ArrayList<>(); final int handle = m_serverInst.addConnectionListener(events::add, false); // trigger a connect event - m_clientInst.startClient("127.0.0.1", 10000); + m_clientInst.startClient(address, 10000); // wait for client to report it's started, then wait another 0.1 sec try {