Skip to content

Commit 6b553df

Browse files
yagotomedouglasmuraoka
authored andcommitted
Fix: getFileName lib to display correctly the filename (#1154)
Fixes #1121 This PR fixes the removal of hex prefix generated by parse server and add tests for this function.
1 parent 6cac9df commit 6b553df

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/lib/getFileName.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ export default function getFileName(name) {
1111
if (name instanceof Parse.File) {
1212
return getFileName(name.name());
1313
}
14-
let offset = 37;
15-
if (name.indexOf('tfss-') === 0) {
16-
offset += 5;
17-
}
14+
const offset = name.indexOf('_') + 1;
1815
return name.substr(offset);
1916
}

src/lib/tests/getFileName.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2016-present, Parse, LLC
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the LICENSE file in
6+
* the root directory of this source tree.
7+
*/
8+
jest.dontMock('../getFileName');
9+
const getFileName = require('../getFileName').default;
10+
const Parse = require('parse');
11+
12+
describe('getFileName', () => {
13+
it('get filename prefixed with hex', () => {
14+
const actualFilename = 'profile.jpg';
15+
expect(getFileName(`7b16230f584b360f667665fcb7d7a98b_${actualFilename}`)).toBe(actualFilename);
16+
17+
const parseFile = new Parse.File(`7b16230f584b360f667665fcb7d7a98b_${actualFilename}`);
18+
expect(getFileName(parseFile)).toBe(actualFilename);
19+
});
20+
21+
it('get filename containing underscore and prefixed with hex', () => {
22+
const actualFilename = 'bg_img.png';
23+
expect(getFileName(`7b16230f584b360f667665fcb7d7a98b_${actualFilename}`)).toBe(actualFilename);
24+
25+
const parseFile = new Parse.File(`7b16230f584b360f667665fcb7d7a98b_${actualFilename}`);
26+
expect(getFileName(parseFile)).toBe(actualFilename);
27+
});
28+
});

0 commit comments

Comments
 (0)