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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix media type lookup case sensitivity #928

Closed
wants to merge 1 commit into from
Closed
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
Expand Up @@ -99,6 +99,7 @@ public List<String> getAllFileExtensions() {
* @return a MediaType for the key or {@code null}
*/
protected MediaType lookupMediaType(String extension) {
extension = extension.toLowerCase(Locale.ENGLISH);
return this.mediaTypes.get(extension);
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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 @@ -51,4 +51,18 @@ public void resolveExtensionsNoMatch() {
assertTrue(extensions.isEmpty());
}

/**
* Unit test for SPR-13747 - ensures that reverse lookup of media type from media
* type key is case-insensitive.
*
* @author Melissa Hartsock
*/
@Test
public void lookupMediaTypeCaseInsensitive() {
Map<String, MediaType> mapping = Collections.singletonMap("json", MediaType.APPLICATION_JSON);
MappingMediaTypeFileExtensionResolver resolver = new MappingMediaTypeFileExtensionResolver(mapping);
MediaType mediaType = resolver.lookupMediaType("JSON");

assertEquals(mediaType, MediaType.APPLICATION_JSON);
}
}