mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-04 04:49:12 +00:00
395794 NullPointerException in when requesting a file without extension
This commit is contained in:
parent
930f567c32
commit
2966192aa4
@ -20,6 +20,7 @@ package org.eclipse.jetty.http;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@ -58,6 +59,14 @@ public class MimeTypesTest
|
||||
assertMimeTypeByExtension("text/plain","TEST.TXT");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMimeByExtension_NoExtension()
|
||||
{
|
||||
MimeTypes mimetypes = new MimeTypes();
|
||||
String contentType = mimetypes.getMimeByExtension("README");
|
||||
assertNull(contentType);
|
||||
}
|
||||
|
||||
private void assertMimeTypeByExtension(String expectedMimeType, String filename)
|
||||
{
|
||||
MimeTypes mimetypes = new MimeTypes();
|
||||
|
@ -382,7 +382,8 @@ public class ResourceCache
|
||||
_key=pathInContext;
|
||||
_resource=resource;
|
||||
|
||||
_contentType=BufferUtil.toBuffer(_mimeTypes.getMimeByExtension(_resource.toString()));
|
||||
String mimeType = _mimeTypes.getMimeByExtension(_resource.toString());
|
||||
_contentType=(mimeType==null?null:BufferUtil.toBuffer(mimeType));
|
||||
boolean exists=resource.exists();
|
||||
_lastModified=exists?resource.lastModified():-1;
|
||||
_lastModifiedBytes=_lastModified<0?null:BufferUtil.toBuffer(HttpFields.formatDate(_lastModified));
|
||||
|
@ -229,6 +229,23 @@ public class ResourceCacheTest
|
||||
cache.flushCache();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoextension() throws Exception
|
||||
{
|
||||
ResourceCollection rc = new ResourceCollection(new String[]{
|
||||
"../jetty-util/src/test/resources/org/eclipse/jetty/util/resource/four/"
|
||||
});
|
||||
|
||||
Resource[] resources = rc.getResources();
|
||||
MimeTypes mime = new MimeTypes();
|
||||
|
||||
ResourceCache cache = new ResourceCache(null,resources[0],mime,false,false);
|
||||
|
||||
assertEquals("4 - four", getContent(cache, "four.txt"));
|
||||
assertEquals("4 - four (no extension)", getContent(cache, "four"));
|
||||
}
|
||||
|
||||
|
||||
static String getContent(Resource r, String path) throws Exception
|
||||
{
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
|
@ -0,0 +1 @@
|
||||
4 - four (no extension)
|
@ -0,0 +1 @@
|
||||
4 - four
|
Loading…
x
Reference in New Issue
Block a user