Skip to content

Commit

Permalink
fix(h5p-server): file format filter now case insensitive (#1313)
Browse files Browse the repository at this point in the history
Fixes #1299.
  • Loading branch information
sr258 authored Apr 22, 2021
1 parent dc46cf4 commit 0bbf7bc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/h5p-server/src/H5PEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ export default class H5PEditor {
throw new H5pError('upload-validation-error', {}, 400);
}

const extension = path.extname(file.name);
const extension = path.extname(file.name).toLowerCase();
const cleanExtension = extension.length > 1 ? extension.substr(1) : '';
if (!this.config.contentWhitelist.split(' ').includes(cleanExtension)) {
throw new H5pError('not-in-whitelist', {
Expand Down
32 changes: 32 additions & 0 deletions packages/h5p-server/test/H5PEditor.saving.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,38 @@ describe('H5PEditor', () => {
);
});

it('stores content files with UPPERCASE extensions', async () => {
await withDir(
async ({ path: tempDirPath }) => {
const { h5pEditor } = createH5PEditor(tempDirPath);
const user = new User();

const originalPath = path.resolve(
'test/data/sample-content/content/earth.jpg'
);
const fileBuffer = fsExtra.readFileSync(originalPath);
const { path: savedFilePath } = await h5pEditor.saveContentFile(
undefined,
{
name: 'image',
type: 'image'
},
{
data: fileBuffer,
mimetype: 'image/jpeg',
name: 'earth.JPG',
size: fsExtra.statSync(originalPath).size
},
user
);

expect(savedFilePath).toBeDefined();
expect(savedFilePath.endsWith('#tmp')).toBeTruthy();
},
{ keep: false, unsafeCleanup: true }
);
});

it('saves content and returns the data', async () => {
await withDir(
async ({ path: tempDirPath }) => {
Expand Down

0 comments on commit 0bbf7bc

Please sign in to comment.