Merge pull request #928 from mhartsock/SPR-13747

This commit is contained in:
Rossen Stoyanchev
2015-12-01 16:53:11 -05:00
2 changed files with 14 additions and 2 deletions

View File

@@ -95,10 +95,12 @@ public class MappingMediaTypeFileExtensionResolver implements MediaTypeFileExten
}
/**
* Use this method for a reverse lookup from extension to MediaType.
* Use this method for a reverse, case-insensitive MediaType lookup.
* @param extension the extension to look up
* @return a MediaType for the key or {@code null}
*/
protected MediaType lookupMediaType(String extension) {
extension = extension.toLowerCase(Locale.ENGLISH);
return this.mediaTypes.get(extension);
}

View File

@@ -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.
@@ -51,4 +51,14 @@ public class MappingMediaTypeFileExtensionResolverTests {
assertTrue(extensions.isEmpty());
}
// SPR-13747
@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);
}
}