diff --git a/src/main/cpp/src/parse_uri.cu b/src/main/cpp/src/parse_uri.cu index cd64c539ef..13c4050404 100644 --- a/src/main/cpp/src/parse_uri.cu +++ b/src/main/cpp/src/parse_uri.cu @@ -500,9 +500,10 @@ __device__ std::pair find_query_part(string_view haystack, st auto h = haystack.data(); auto const end_h = haystack.data() + find_length; auto n = needle.data(); + bool match = false; while (h < end_h) { - bool match = true; - for (size_type jdx = 0; match && (jdx < n_bytes); ++jdx) { + match = false; // initialize to false to prevent empty query key + for (size_type jdx = 0; (jdx == 0 || match) && (jdx < n_bytes); ++jdx) { match = (h[jdx] == n[jdx]); } if (match) { match = n_bytes < haystack.size_bytes() && h[n_bytes] == '='; } @@ -519,8 +520,8 @@ __device__ std::pair find_query_part(string_view haystack, st h++; } - // if h is past the end of the haystack, no match. - if (haystack.data() + haystack.size_bytes() <= h || *h != '=') { return {{}, false}; } + // if not match or no value, return nothing + if (!match || *h != '=') { return {{}, false}; } // skip over the = h++; diff --git a/src/test/java/com/nvidia/spark/rapids/jni/ParseURITest.java b/src/test/java/com/nvidia/spark/rapids/jni/ParseURITest.java index f8ed45c704..8f9fcfd903 100644 --- a/src/test/java/com/nvidia/spark/rapids/jni/ParseURITest.java +++ b/src/test/java/com/nvidia/spark/rapids/jni/ParseURITest.java @@ -214,8 +214,11 @@ void parseURISparkTest() { "https://[::1]/?invalid=param&~.=!@&^", "userinfo@www.nvidia.com/path?query=1#Ref", "", - null}; - + null, + "https://www.nvidia.com/?cat=12", + "www.nvidia.com/vote.php?pid=50", + "https://www.nvidia.com/vote.php?=50", + }; String[] queries = { "a", @@ -270,7 +273,11 @@ void parseURISparkTest() { "invalid", "query", "a", - "f"}; + "f", + "query", + "query", + "" + }; testProtocol(testData); testHost(testData);