Skip to content

Commit 09008bf

Browse files
author
Marc Derhammer
committed
fix: use last index of period to determine extension
related to #8753
1 parent 0593985 commit 09008bf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

spec/ParseFile.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,30 @@ describe('Parse.File testing', () => {
13641364
);
13651365
});
13661366

1367+
it('works with a period in the file name', async () => {
1368+
await reconfigureServer({
1369+
fileUpload: {
1370+
enableForPublic: true,
1371+
},
1372+
});
1373+
const headers = {
1374+
'X-Parse-Application-Id': 'test',
1375+
'X-Parse-REST-API-Key': 'rest',
1376+
};
1377+
await expectAsync(
1378+
request({
1379+
method: 'POST',
1380+
headers: headers,
1381+
url: 'http://localhost:8378/1/files/file.png.html',
1382+
body: '<html></html>\n',
1383+
}).catch(e => {
1384+
throw new Error(e.data.error);
1385+
})
1386+
).toBeRejectedWith(
1387+
new Parse.Error(Parse.Error.FILE_SAVE_ERROR, `File upload of extension html is disabled.`)
1388+
);
1389+
});
1390+
13671391
it('works with array', async () => {
13681392
await reconfigureServer({
13691393
fileUpload: {

src/Routers/FilesRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class FilesRouter {
155155
};
156156
let extension = contentType;
157157
if (filename && filename.includes('.')) {
158-
extension = filename.split('.')[1];
158+
extension = filename.split('.')[filename.split('.').length - 1];
159159
} else if (contentType && contentType.includes('/')) {
160160
extension = contentType.split('/')[1];
161161
}

0 commit comments

Comments
 (0)