From e3e21004b96e61fc0e75f1097418aff8c8d1d4b4 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Mon, 15 Apr 2024 14:41:16 +0200 Subject: [PATCH] fix (core): Make *.jsonld have UTF-8 encoding by default --- .../java/dev/enola/common/io/mediatype/MediaTypeDetector.java | 4 ++++ .../java/dev/enola/common/io/mediatype/YamlMediaType.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/common/common/src/main/java/dev/enola/common/io/mediatype/MediaTypeDetector.java b/common/common/src/main/java/dev/enola/common/io/mediatype/MediaTypeDetector.java index 162fe57b8..0660a3e50 100644 --- a/common/common/src/main/java/dev/enola/common/io/mediatype/MediaTypeDetector.java +++ b/common/common/src/main/java/dev/enola/common/io/mediatype/MediaTypeDetector.java @@ -217,11 +217,15 @@ public MediaType detect(String contentType, String contentEncoding, URI uri) { if (mediaType.is(MediaType.ANY_TEXT_TYPE)) { // TODO Remove this; it's wrong! Generic text cannot just be assumed to be UTF-8! mediaType = mediaType.withCharset(Charsets.UTF_8); + // TODO This should move into a TBD JsonMediaType implements ResourceCharsetDetector } else if (mediaType.is(MediaType.JSON_UTF_8.withoutParameters())) { // TODO See ResourceCharsetDetector above; implement JSON BOM detection à la §3 from // https://www.ietf.org/rfc/rfc4627.txt in a new class JsonResourceCharsetDetector mediaType = mediaType.withCharset(Charsets.UTF_8); + } else if (mediaType.subtype().endsWith("+json")) { + mediaType = mediaType.withCharset(Charsets.UTF_8); } + // TODO NOT if (mediaType.subtype().endsWith("+yaml")) { but via YamlMediaType } return mediaType; diff --git a/common/common/src/main/java/dev/enola/common/io/mediatype/YamlMediaType.java b/common/common/src/main/java/dev/enola/common/io/mediatype/YamlMediaType.java index 00a3f1b1b..b753951c5 100644 --- a/common/common/src/main/java/dev/enola/common/io/mediatype/YamlMediaType.java +++ b/common/common/src/main/java/dev/enola/common/io/mediatype/YamlMediaType.java @@ -34,6 +34,8 @@ public class YamlMediaType extends ResourceCharsetDetectorSPI implements MediaTypeProvider { // TODO Move this into e.g. dev.enola.format.yaml ? + // TODO How to allow this to express mediaType.subtype().endsWith("+yaml") ? + // https://www.ietf.org/archive/id/draft-ietf-httpapi-yaml-mediatypes-00.html // https://github.com/ietf-wg-httpapi/mediatypes/blob/main/draft-ietf-httpapi-yaml-mediatypes.md