Skip to content

Commit 9c34fae

Browse files
authored
Fix a parse_uri query bug (#1740)
* Fix a parse_uri query bug Signed-off-by: Haoyang Li <[email protected]> * Add comments Signed-off-by: Haoyang Li <[email protected]> --------- Signed-off-by: Haoyang Li <[email protected]>
1 parent cd0b857 commit 9c34fae

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/main/cpp/src/parse_uri.cu

+5-4
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,10 @@ __device__ std::pair<string_view, bool> find_query_part(string_view haystack, st
500500
auto h = haystack.data();
501501
auto const end_h = haystack.data() + find_length;
502502
auto n = needle.data();
503+
bool match = false;
503504
while (h < end_h) {
504-
bool match = true;
505-
for (size_type jdx = 0; match && (jdx < n_bytes); ++jdx) {
505+
match = false; // initialize to false to prevent empty query key
506+
for (size_type jdx = 0; (jdx == 0 || match) && (jdx < n_bytes); ++jdx) {
506507
match = (h[jdx] == n[jdx]);
507508
}
508509
if (match) { match = n_bytes < haystack.size_bytes() && h[n_bytes] == '='; }
@@ -519,8 +520,8 @@ __device__ std::pair<string_view, bool> find_query_part(string_view haystack, st
519520
h++;
520521
}
521522

522-
// if h is past the end of the haystack, no match.
523-
if (haystack.data() + haystack.size_bytes() <= h || *h != '=') { return {{}, false}; }
523+
// if not match or no value, return nothing
524+
if (!match || *h != '=') { return {{}, false}; }
524525

525526
// skip over the =
526527
h++;

src/test/java/com/nvidia/spark/rapids/jni/ParseURITest.java

+10-3
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,11 @@ void parseURISparkTest() {
214214
"https://[::1]/?invalid=param&~.=!@&^",
215215
"[email protected]/path?query=1#Ref",
216216
"",
217-
null};
218-
217+
null,
218+
"https://www.nvidia.com/?cat=12",
219+
"www.nvidia.com/vote.php?pid=50",
220+
"https://www.nvidia.com/vote.php?=50",
221+
};
219222

220223
String[] queries = {
221224
"a",
@@ -270,7 +273,11 @@ void parseURISparkTest() {
270273
"invalid",
271274
"query",
272275
"a",
273-
"f"};
276+
"f",
277+
"query",
278+
"query",
279+
""
280+
};
274281

275282
testProtocol(testData);
276283
testHost(testData);

0 commit comments

Comments
 (0)