Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

Commit 423594a

Browse files
committed
chore: add error message sanitization
1 parent 9fa4bae commit 423594a

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtility.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,14 +677,16 @@ static Map<String, String> parseUrl(String url) {
677677
String key = kv[0].trim();
678678
if (kv.length == 1) {
679679
if (!key.isEmpty()) {
680-
throw new BigQueryJdbcRuntimeException("Property '" + key + "' has no value.");
680+
String safeKey = key.length() > 32 ? key.substring(0, 32) + "..." : key;
681+
throw new BigQueryJdbcRuntimeException("Property '" + safeKey + "' has no value.");
681682
}
682683
} else {
683684
String value = kv[1]; // Value might be empty string if "Key="
684685
if (!key.isEmpty()) {
685686
String upperCaseKey = key.toUpperCase();
686687
if (!PROPERTY_NAME_MAP.containsKey(upperCaseKey)) {
687-
throw new BigQueryJdbcRuntimeException("Unknown property: " + key);
688+
String safeKey = key.length() > 32 ? key.substring(0, 32) + "..." : key;
689+
throw new BigQueryJdbcRuntimeException("Unknown property: " + safeKey);
688690
}
689691
map.put(PROPERTY_NAME_MAP.get(upperCaseKey), CharEscapers.decodeUriPath(value));
690692
}

google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtilityTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,21 @@ public void testConnectionPropertiesFromURIMultilineNoSemicolon() {
145145
.isEqualTo("value1\nvalue2");
146146
}
147147

148+
@Test
149+
public void testParseUrl_longUnknownProperty_sanitized() {
150+
String longKey = String.join("", Collections.nCopies(50, "a"));
151+
String url = "jdbc:bigquery://https://www.googleapis.com/bigquery/v2:443;" + longKey + "=value";
152+
153+
BigQueryJdbcRuntimeException e =
154+
assertThrows(
155+
BigQueryJdbcRuntimeException.class, () -> BigQueryJdbcUrlUtility.parseUrl(url));
156+
157+
assertThat(e.getMessage()).contains("Unknown property:");
158+
assertThat(e.getMessage()).contains("...");
159+
assertThat(e.getMessage()).doesNotContain(longKey);
160+
assertThat(e.getMessage().length()).isLessThan(100);
161+
}
162+
148163
@Test
149164
public void testOverridePropertiesFromURICompatibility() {
150165
String connection_uri =

0 commit comments

Comments
 (0)