Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: Fix unicode handling in HTTPClient #8046

Merged
merged 1 commit into from Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions core/src/main/java/org/apache/iceberg/rest/HTTPClient.java
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -105,7 +106,7 @@ private static String extractResponseBodyAsString(CloseableHttpResponse response
}

// 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");
}
Expand Down Expand Up @@ -471,13 +472,13 @@ public HTTPClient build() {

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);
}
}
Expand Up @@ -73,19 +73,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
Expand Down