Skip to content

Commit a27cd13

Browse files
committed
Use URIBuilder for SPOG query param parsing
Replace manual string splitting of ?o= from httpPath with Apache URIBuilder.getQueryParams() as suggested in code review. Signed-off-by: Madhavendra Rathore <[email protected]> Co-authored-by: Isaac Signed-off-by: Madhavendra Rathore <[email protected]>
1 parent 2f21d4d commit a27cd13

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

src/main/java/com/databricks/jdbc/api/impl/DatabricksConnectionContext.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,16 +1186,20 @@ private Map<String, String> parseCustomHeaders(ImmutableMap<String, String> para
11861186
String httpPath =
11871187
parameters.getOrDefault(
11881188
DatabricksJdbcUrlParams.HTTP_PATH.getParamName().toLowerCase(), "");
1189-
int queryStart = httpPath.indexOf('?');
1190-
if (queryStart >= 0) {
1191-
String queryString = httpPath.substring(queryStart + 1);
1192-
for (String param : queryString.split("&")) {
1193-
String[] kv = param.split("=", 2);
1194-
if (kv.length == 2 && "o".equals(kv[0]) && !kv[1].isEmpty()) {
1195-
headers.put(ORG_ID_HEADER, kv[1]);
1189+
try {
1190+
List<org.apache.http.NameValuePair> queryParams =
1191+
new org.apache.http.client.utils.URIBuilder("http://placeholder" + httpPath)
1192+
.getQueryParams();
1193+
for (org.apache.http.NameValuePair param : queryParams) {
1194+
if ("o".equals(param.getName())
1195+
&& param.getValue() != null
1196+
&& !param.getValue().isEmpty()) {
1197+
headers.put(ORG_ID_HEADER, param.getValue());
11961198
break;
11971199
}
11981200
}
1201+
} catch (java.net.URISyntaxException e) {
1202+
// Malformed httpPath — skip SPOG header extraction
11991203
}
12001204
}
12011205

0 commit comments

Comments
 (0)