Skip to content

Commit

Permalink
Remove trailing space from media type for ots mapping
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wilkinsona committed Feb 11, 2022
1 parent c3eee4a commit 387795d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -128,7 +128,7 @@ public final class MimeMappings implements Iterable<MimeMappings.Mapping> {
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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -135,4 +136,11 @@ void makeUnmodifiable() {
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));
}

}

0 comments on commit 387795d

Please sign in to comment.