From 387795d4db15022ec94ad6b53f846514217ed66e Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 11 Feb 2022 14:09:53 +0000 Subject: [PATCH] Remove trailing space from media type for ots mapping The regular expression in the new test is intended to match the documented [1] ABNF for a media type: type-name = reg-name subtype-name = reg-name reg-name = 1*127reg-name-chars reg-name-chars = ALPHA / DIGIT / "!" / "#" / "$" / "&" / "." / "+" / "-" / "^" / "_" Closes gh-29746 [1] https://datatracker.ietf.org/doc/html/rfc4288#section-4.2 --- .../springframework/boot/web/server/MimeMappings.java | 4 ++-- .../boot/web/server/MimeMappingsTests.java | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java index 2cda5234e8..3928bcc2bb 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/server/MimeMappings.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -128,7 +128,7 @@ public final class MimeMappings implements Iterable { mappings.add("otg", "application/vnd.oasis.opendocument.graphics-template"); mappings.add("oth", "application/vnd.oasis.opendocument.text-web"); mappings.add("otp", "application/vnd.oasis.opendocument.presentation-template"); - mappings.add("ots", "application/vnd.oasis.opendocument.spreadsheet-template "); + mappings.add("ots", "application/vnd.oasis.opendocument.spreadsheet-template"); mappings.add("ott", "application/vnd.oasis.opendocument.text-template"); mappings.add("ogx", "application/ogg"); mappings.add("ogv", "video/ogg"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java index 7c8e2347dd..b28a8e5dcc 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/server/MimeMappingsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import org.junit.jupiter.api.Test; @@ -135,4 +136,11 @@ class MimeMappingsTests { assertThat(unmodifiable.get("foo")).isNull(); } + @Test + void mimeTypesInDefaultMappingsAreCorrectlyStructured() { + String regName = "[A-Za-z0-9!#$&.+\\-^_]{1,127}"; + Pattern pattern = Pattern.compile("^" + regName + "\\/" + regName + "$"); + assertThat(MimeMappings.DEFAULT).allSatisfy((mapping) -> assertThat(mapping.getMimeType()).matches(pattern)); + } + }