|
7 | 7 | import com.clickhouse.jdbc.Driver; |
8 | 8 | import com.google.common.collect.ImmutableMap; |
9 | 9 |
|
| 10 | +import java.io.UnsupportedEncodingException; |
10 | 11 | import java.net.URI; |
11 | 12 | import java.net.URISyntaxException; |
12 | 13 | import java.net.URLDecoder; |
13 | 14 | import java.nio.charset.StandardCharsets; |
| 15 | +import java.nio.charset.UnsupportedCharsetException; |
14 | 16 | import java.sql.DriverPropertyInfo; |
15 | 17 | import java.sql.SQLException; |
16 | 18 | import java.util.Comparator; |
@@ -195,19 +197,23 @@ private Map<String, String> parseUrl(String url) throws SQLException { |
195 | 197 | } |
196 | 198 | if (uri.getQuery() != null && !uri.getQuery().trim().isEmpty()) { |
197 | 199 | for (String pair : uri.getRawQuery().split("&")) { |
198 | | - String[] p = pair.split("=", 2); |
199 | | - if (p.length != 2 || p[0] == null || p[1] == null) { |
200 | | - throw new SQLException("Invalid query parameter '" + pair + "'"); |
| 200 | + try { |
| 201 | + String[] p = pair.split("=", 2); |
| 202 | + if (p.length != 2 || p[0] == null || p[1] == null) { |
| 203 | + throw new SQLException("Invalid query parameter '" + pair + "'"); |
| 204 | + } |
| 205 | + String key = URLDecoder.decode(p[0], StandardCharsets.UTF_8.name()); |
| 206 | + if (key == null || key.trim().isEmpty() || !PATTERN_HTTP_TOKEN.matcher(key).matches()) { |
| 207 | + throw new SQLException("Invalid query parameter key in pair'" + pair + "'"); |
| 208 | + } |
| 209 | + String value = URLDecoder.decode(p[1], StandardCharsets.UTF_8.name()); |
| 210 | + if (value == null || value.trim().isEmpty() || "=".equals(value)) { |
| 211 | + throw new SQLException("Invalid query parameter value in pair '" + pair + "'"); |
| 212 | + } |
| 213 | + properties.put(key.trim(), value); |
| 214 | + } catch (UnsupportedEncodingException e) { |
| 215 | + throw new SQLException("Internal error'", e); |
201 | 216 | } |
202 | | - String key = URLDecoder.decode(p[0], StandardCharsets.UTF_8); |
203 | | - if (key == null || key.trim().isEmpty() || !PATTERN_HTTP_TOKEN.matcher(key).matches()) { |
204 | | - throw new SQLException("Invalid query parameter key in pair'" + pair + "'"); |
205 | | - } |
206 | | - String value = URLDecoder.decode(p[1], StandardCharsets.UTF_8); |
207 | | - if (value == null || value.trim().isEmpty() || "=".equals(value)) { |
208 | | - throw new SQLException("Invalid query parameter value in pair '" + pair + "'"); |
209 | | - } |
210 | | - properties.put(key.trim(), value); |
211 | 217 | } |
212 | 218 | } |
213 | 219 | return properties; |
|
0 commit comments