This is an automated email from the ASF dual-hosted git repository.
dweeks pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iceberg.git
The following commit(s) were added to refs/heads/master by this push:
new 9572585779 Core: Fix unicode handling in HTTPClient (#8046)
9572585779 is described below
commit 95725857791333f4fa8a8db6d37472cd457cb9f9
Author: Eduard Tudenhoefner <[email protected]>
AuthorDate: Thu Jul 13 19:41:07 2023 +0200
Core: Fix unicode handling in HTTPClient (#8046)
fixes #7821
Without the fix, tests would fail with
```
expected: struct<1: id: required int (unique ID 🤪), 2: data: required
string>
but was: struct<1: id: required int (unique ID ?), 2: data: required
string>
```
---
core/src/main/java/org/apache/iceberg/rest/HTTPClient.java | 7 ++++---
core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java | 6 +++---
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/core/src/main/java/org/apache/iceberg/rest/HTTPClient.java
b/core/src/main/java/org/apache/iceberg/rest/HTTPClient.java
index 9af4b56797..b2b6fc8a7c 100644
--- a/core/src/main/java/org/apache/iceberg/rest/HTTPClient.java
+++ b/core/src/main/java/org/apache/iceberg/rest/HTTPClient.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@@ -105,7 +106,7 @@ public class HTTPClient implements RESTClient {
}
// EntityUtils.toString returns null when HttpEntity.getContent returns
null.
- return EntityUtils.toString(response.getEntity(), "UTF-8");
+ return EntityUtils.toString(response.getEntity(),
StandardCharsets.UTF_8);
} catch (IOException | ParseException e) {
throw new RESTException(e, "Failed to convert HTTP response body to
string");
}
@@ -471,13 +472,13 @@ public class HTTPClient implements RESTClient {
private StringEntity toJson(Object requestBody) {
try {
- return new StringEntity(mapper.writeValueAsString(requestBody));
+ return new StringEntity(mapper.writeValueAsString(requestBody),
StandardCharsets.UTF_8);
} catch (JsonProcessingException e) {
throw new RESTException(e, "Failed to write request body: %s",
requestBody);
}
}
private StringEntity toFormEncoding(Map<?, ?> formData) {
- return new StringEntity(RESTUtil.encodeFormData(formData));
+ return new StringEntity(RESTUtil.encodeFormData(formData),
StandardCharsets.UTF_8);
}
}
diff --git a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
index 5641dce89f..203b5fc381 100644
--- a/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
+++ b/core/src/test/java/org/apache/iceberg/catalog/CatalogTests.java
@@ -74,19 +74,19 @@ public abstract class CatalogTests<C extends Catalog &
SupportsNamespaces> {
// Schema passed to create tables
protected static final Schema SCHEMA =
new Schema(
- required(3, "id", Types.IntegerType.get(), "unique ID"),
+ required(3, "id", Types.IntegerType.get(), "unique ID 🤪"),
required(4, "data", Types.StringType.get()));
// This is the actual schema for the table, with column IDs reassigned
private static final Schema TABLE_SCHEMA =
new Schema(
- required(1, "id", Types.IntegerType.get(), "unique ID"),
+ required(1, "id", Types.IntegerType.get(), "unique ID 🤪"),
required(2, "data", Types.StringType.get()));
// This is the actual schema for the table, with column IDs reassigned
private static final Schema REPLACE_SCHEMA =
new Schema(
- required(2, "id", Types.IntegerType.get(), "unique ID"),
+ required(2, "id", Types.IntegerType.get(), "unique ID 🤪"),
required(3, "data", Types.StringType.get()));
// another schema that is not the same