Skip to content

Commit 087ddb8

Browse files
committed
Add tests for case differences.
1 parent 2e038c0 commit 087ddb8

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

lib/handlers/resource-mapper.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ class ResourceMapper {
2727

2828
// Map to the filename on disk, appending the extension of different from the URL
2929
const extension = contentType in extensions ? `.${extensions[contentType][0]}` : '.unknown'
30-
const suffix = extension === urlExtension ? extension : `${urlExtension}$${extension}`
30+
const correctExtension = types[urlExtension.substr(1).toLowerCase()] === contentType
31+
const suffix = correctExtension ? urlExtension : `${urlExtension}$${extension}`
3132
const path = `${this._rootPath}${urlPath}${suffix}`
3233

3334
return { path, contentType: contentType || DEFAULT_CONTENTTYPE }

test/unit/resource-mapper-test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,39 @@ describe('ResourceMapper', () => {
5959
contentType: 'application/octet-stream'
6060
})
6161

62+
itMapsUrl(mapper, 'a URL with an alternative extension that matches the content type',
63+
{
64+
url: 'http://localhost/space/foo.jpeg',
65+
contentType: 'image/jpeg',
66+
createIfNotExists: true
67+
},
68+
{
69+
path: `${rootPath}space/foo.jpeg`,
70+
contentType: 'image/jpeg'
71+
})
72+
73+
itMapsUrl(mapper, 'a URL with an uppercase extension that matches the content type',
74+
{
75+
url: 'http://localhost/space/foo.JPG',
76+
contentType: 'image/jpeg',
77+
createIfNotExists: true
78+
},
79+
{
80+
path: `${rootPath}space/foo.JPG`,
81+
contentType: 'image/jpeg'
82+
})
83+
84+
itMapsUrl(mapper, 'a URL with a mixed-case extension that matches the content type',
85+
{
86+
url: 'http://localhost/space/foo.jPeG',
87+
contentType: 'image/jpeg',
88+
createIfNotExists: true
89+
},
90+
{
91+
path: `${rootPath}space/foo.jPeG`,
92+
contentType: 'image/jpeg'
93+
})
94+
6295
// GET/HEAD/POST/DELETE/PATCH base cases
6396

6497
itMapsUrl.skip(mapper, 'a URL of a non-existing file',

0 commit comments

Comments
 (0)