Skip to content

Added the option to only keep the last part of the original filename as the extension if the keepExtensions option is set to true #888

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

Closed
wants to merge 1 commit into from
Closed
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
9 changes: 5 additions & 4 deletions src/Formidable.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const DEFAULT_OPTIONS = {
return true;
},
filename: undefined,
longExtentions: false
};

function hasOwnProp(obj, key) {
Expand Down Expand Up @@ -510,7 +511,7 @@ class IncomingForm extends EventEmitter {
// able to get composed extension with multiple dots
// "a.b.c" -> ".b.c"
// as opposed to path.extname -> ".c"
_getExtension(str) {
_getExtension(str, long) {
if (!str) {
return '';
}
Expand All @@ -520,8 +521,8 @@ class IncomingForm extends EventEmitter {
const lastDot = basename.lastIndexOf('.');
let rawExtname = path.extname(basename);

if (firstDot !== lastDot) {
rawExtname = basename.slice(firstDot);
if (long && firstDot !== lastDot) {
rawExtname = basename.slice(firstDot);
}

let filtered;
Expand Down Expand Up @@ -570,7 +571,7 @@ class IncomingForm extends EventEmitter {
if (part && this.options.keepExtensions) {
const originalFilename =
typeof part === 'string' ? part : part.originalFilename;
return `${name}${this._getExtension(originalFilename)}`;
return `${name}${this._getExtension(originalFilename, this.options.longExtentions)}`;
}

return name;
Expand Down