Skip to content

Fix getFileName lib to display correctly the filename #1154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/lib/getFileName.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ export default function getFileName(name) {
if (name instanceof Parse.File) {
return getFileName(name.name());
}
let offset = 37;
if (name.indexOf('tfss-') === 0) {
offset += 5;
}
const offset = name.indexOf('_') + 1;
return name.substr(offset);
}
28 changes: 28 additions & 0 deletions src/lib/tests/getFileName.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2016-present, Parse, LLC
* All rights reserved.
*
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
jest.dontMock('../getFileName');
const getFileName = require('../getFileName').default;
const Parse = require('parse');

describe('getFileName', () => {
it('get filename prefixed with hex', () => {
const actualFilename = 'profile.jpg';
expect(getFileName(`7b16230f584b360f667665fcb7d7a98b_${actualFilename}`)).toBe(actualFilename);

const parseFile = new Parse.File(`7b16230f584b360f667665fcb7d7a98b_${actualFilename}`);
expect(getFileName(parseFile)).toBe(actualFilename);
});

it('get filename containing underscore and prefixed with hex', () => {
const actualFilename = 'bg_img.png';
expect(getFileName(`7b16230f584b360f667665fcb7d7a98b_${actualFilename}`)).toBe(actualFilename);

const parseFile = new Parse.File(`7b16230f584b360f667665fcb7d7a98b_${actualFilename}`);
expect(getFileName(parseFile)).toBe(actualFilename);
});
});