diff --git a/pulsar-client-cpp/lib/auth/athenz/ZTSClient.cc b/pulsar-client-cpp/lib/auth/athenz/ZTSClient.cc index 68a0b8070cec0..5c37f48d90cf0 100644 --- a/pulsar-client-cpp/lib/auth/athenz/ZTSClient.cc +++ b/pulsar-client-cpp/lib/auth/athenz/ZTSClient.cc @@ -46,8 +46,10 @@ namespace ptree = boost::property_tree; #ifdef PULSAR_USE_BOOST_REGEX #include +#define PULSAR_REGEX_NAMESPACE boost #else #include +#define PULSAR_REGEX_NAMESPACE std #endif DECLARE_LOG_OBJECT() @@ -365,27 +367,15 @@ const std::string ZTSClient::getHeader() const { return roleHeader_; } PrivateKeyUri ZTSClient::parseUri(const char *uri) { PrivateKeyUri uriSt; // scheme mediatype[;base64] path file - -#ifdef PULSAR_USE_BOOST_REGEX - static const boost::regex expression( - "^(\?:([^:/\?#]+):)(\?:([;/\\-\\w]*),)\?(/\?(\?:[^\?#/]*/)*)\?([^\?#]*)"); - boost::cmatch groups; - if (boost::regex_match(uri, groups, expression)) { - uriSt.scheme = groups.str(1); - uriSt.mediaTypeAndEncodingType = groups.str(2); - uriSt.data = groups.str(4); - } -#else // !PULSAR_USE_BOOST_REGEX - static const std::regex expression( - R"(^(?:([A-Za-z]+):)(?:([/\w\-]+;\w+),([=\w]+))?(?:\/\/)?(\/[^?#]+)?)"); - std::cmatch groups; - if (std::regex_match(uri, groups, expression)) { + static const PULSAR_REGEX_NAMESPACE::regex expression( + R"(^(?:([A-Za-z]+):)(?:([/\w\-]+;\w+),([=\w]+))?(?:\/\/)?([^?#]+)?)"); + PULSAR_REGEX_NAMESPACE::cmatch groups; + if (PULSAR_REGEX_NAMESPACE::regex_match(uri, groups, expression)) { uriSt.scheme = groups.str(1); uriSt.mediaTypeAndEncodingType = groups.str(2); uriSt.data = groups.str(3); uriSt.path = groups.str(4); } -#endif // PULSAR_USE_BOOST_REGEX return uriSt; } } // namespace pulsar diff --git a/pulsar-client-cpp/tests/ZTSClientTest.cc b/pulsar-client-cpp/tests/ZTSClientTest.cc index 01c2e03381668..b338e79555166 100644 --- a/pulsar-client-cpp/tests/ZTSClientTest.cc +++ b/pulsar-client-cpp/tests/ZTSClientTest.cc @@ -42,6 +42,18 @@ TEST(ZTSClientTest, testZTSClient) { ASSERT_EQ("/path/to/private.key", uri.path); } + { + PrivateKeyUri uri = ZTSClientWrapper::parseUri("file:./path/to/private.key"); + ASSERT_EQ("file", uri.scheme); + ASSERT_EQ("./path/to/private.key", uri.path); + } + + { + PrivateKeyUri uri = ZTSClientWrapper::parseUri("file://./path/to/private.key"); + ASSERT_EQ("file", uri.scheme); + ASSERT_EQ("./path/to/private.key", uri.path); + } + { PrivateKeyUri uri = ZTSClientWrapper::parseUri("data:application/x-pem-file;base64,SGVsbG8gV29ybGQK"); ASSERT_EQ("data", uri.scheme);