diff --git a/client/js/dnd.js b/client/js/dnd.js index 5c69f9e70..126df5250 100644 --- a/client/js/dnd.js +++ b/client/js/dnd.js @@ -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(); }, @@ -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(), @@ -304,6 +308,9 @@ qq.DragAndDrop = function(o) { }); } }); + + this._testing = {}; + this._testing.extractDirectoryPath = extractDirectoryPath; }; qq.DragAndDrop.callbacks = function() { diff --git a/client/js/version.js b/client/js/version.js index cfb31675a..ff563d68a 100644 --- a/client/js/version.js +++ b/client/js/version.js @@ -1,2 +1,2 @@ /*global qq */ -qq.version = "5.15.6"; +qq.version = "5.15.7"; diff --git a/package.json b/package.json index 22fba21eb..59ef028c9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/unit/dnd.js b/test/unit/dnd.js index 16ec51a27..249bcbfa6 100644 --- a/test/unit/dnd.js +++ b/test/unit/dnd.js @@ -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/"); + }); });