Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
fix(dnd.js): qqpath wrong if file name occurs in parent dir (#1977)
Browse files Browse the repository at this point in the history
fixes #1976
  • Loading branch information
ogvolkov authored and rnicholus committed Mar 2, 2018
1 parent 2466ccc commit 007c4de
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
33 changes: 20 additions & 13 deletions client/js/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,7 @@ qq.DragAndDrop = function(o) {

if (entry.isFile) {
entry.file(function(file) {
var name = entry.name,
fullPath = entry.fullPath,
indexOfNameInFullPath = fullPath.indexOf(name);

// remove file name from full path string
fullPath = fullPath.substr(0, indexOfNameInFullPath);

// remove leading slash in full path string
if (fullPath.charAt(0) === "/") {
fullPath = fullPath.substr(1);
}

file.qqPath = fullPath;
file.qqPath = extractDirectoryPath(entry);
droppedFiles.push(file);
parseEntryPromise.success();
},
Expand Down Expand Up @@ -85,6 +73,22 @@ qq.DragAndDrop = function(o) {
return parseEntryPromise;
}

function extractDirectoryPath(entry) {
var name = entry.name,
fullPath = entry.fullPath,
indexOfNameInFullPath = fullPath.lastIndexOf(name);

// remove file name from full path string
fullPath = fullPath.substr(0, indexOfNameInFullPath);

// remove leading slash in full path string
if (fullPath.charAt(0) === "/") {
fullPath = fullPath.substr(1);
}

return fullPath;
}

// Promissory. Guaranteed to read all files in the root of the passed directory.
function getFilesInDirectory(entry, reader, accumEntries, existingPromise) {
var promise = existingPromise || new qq.Promise(),
Expand Down Expand Up @@ -304,6 +308,9 @@ qq.DragAndDrop = function(o) {
});
}
});

this._testing = {};
this._testing.extractDirectoryPath = extractDirectoryPath;
};

qq.DragAndDrop.callbacks = function() {
Expand Down
2 changes: 1 addition & 1 deletion client/js/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
/*global qq */
qq.version = "5.15.6";
qq.version = "5.15.7";
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"title": "Fine Uploader",
"main": "lib/traditional.js",
"types" : "typescript/fine-uploader.d.ts",
"version": "5.15.6",
"version": "5.15.7",
"description": "Multiple file upload plugin with progress-bar, drag-and-drop, direct-to-S3 & Azure uploading, client-side image scaling, preview generation, form support, chunking, auto-resume, and tons of other features.",
"keywords": [
"amazon",
Expand Down
25 changes: 25 additions & 0 deletions test/unit/dnd.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,29 @@ describe("drag and drop", function () {
assert(uploadDropZone._testing.isValidFileDrag(ieFileDragEvent), "IE file drag events are valid file drags");
});

it("extracts directory path from entries", function() {
var dnd = new qq.DragAndDrop();

var entry = {
name: "a.txt",
fullPath: "/data/a.txt"
};

var directoryPath = dnd._testing.extractDirectoryPath(entry);

assert.equal(directoryPath, "data/");
});

it("properly extracts directory path when file name occurs in parent directory names", function() {
var dnd = new qq.DragAndDrop();

var entry = {
name: "data",
fullPath: "/data/data"
};

var directoryPath = dnd._testing.extractDirectoryPath(entry);

assert.equal(directoryPath, "data/");
});
});

0 comments on commit 007c4de

Please sign in to comment.