Skip to content

Commit 122c209

Browse files
committed
Fix diffTypesFor() when using a file extension
The `diffTypesFor()` function is intended to allow you to pass in a MediaType object, media type string, or a file extension (e.g. `".pdf"`). However, it turns out the file extension is broken (I guess we have pretty much stopped using file extensions since we improved media type support way back when...). This fixes the issue and adds a test. This bug was originally uncovered by @BeckettFrey in #1095.
1 parent 0690a1d commit 122c209

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* eslint-env jest */
2+
3+
import { diffTypes, diffTypesFor } from '../diff-types';
4+
import MediaType from '../../scripts/media-type';
5+
6+
describe('diffTypesFor', () => {
7+
it('accepts a file extension', () => {
8+
const result = diffTypesFor('.html');
9+
expect(result).toContain(diffTypes.HIGHLIGHTED_RENDERED);
10+
});
11+
12+
it('accepts a media type string', () => {
13+
const result = diffTypesFor('text/html');
14+
expect(result).toContain(diffTypes.HIGHLIGHTED_RENDERED);
15+
});
16+
17+
it('accepts a MediaType object', () => {
18+
const result = diffTypesFor(MediaType('text', 'html'));
19+
expect(result).toContain(diffTypes.HIGHLIGHTED_RENDERED);
20+
});
21+
});

src/constants/diff-types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const diffTypesByMediaType = {
8181
export function diffTypesFor (mediaType) {
8282
let type = null;
8383
if (typeof mediaType === 'string' && mediaType.startsWith('.')) {
84-
type = mediaTypeForExtension(mediaType) || unknownType;
84+
type = mediaTypeForExtension[mediaType] || unknownType;
8585
}
8686
else {
8787
type = parseMediaType(mediaType);

0 commit comments

Comments
 (0)