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

Commit 007c4de

Browse files
ogvolkovrnicholus
authored andcommitted
fix(dnd.js): qqpath wrong if file name occurs in parent dir (#1977)
fixes #1976
1 parent 2466ccc commit 007c4de

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

client/js/dnd.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,7 @@ qq.DragAndDrop = function(o) {
3434

3535
if (entry.isFile) {
3636
entry.file(function(file) {
37-
var name = entry.name,
38-
fullPath = entry.fullPath,
39-
indexOfNameInFullPath = fullPath.indexOf(name);
40-
41-
// remove file name from full path string
42-
fullPath = fullPath.substr(0, indexOfNameInFullPath);
43-
44-
// remove leading slash in full path string
45-
if (fullPath.charAt(0) === "/") {
46-
fullPath = fullPath.substr(1);
47-
}
48-
49-
file.qqPath = fullPath;
37+
file.qqPath = extractDirectoryPath(entry);
5038
droppedFiles.push(file);
5139
parseEntryPromise.success();
5240
},
@@ -85,6 +73,22 @@ qq.DragAndDrop = function(o) {
8573
return parseEntryPromise;
8674
}
8775

76+
function extractDirectoryPath(entry) {
77+
var name = entry.name,
78+
fullPath = entry.fullPath,
79+
indexOfNameInFullPath = fullPath.lastIndexOf(name);
80+
81+
// remove file name from full path string
82+
fullPath = fullPath.substr(0, indexOfNameInFullPath);
83+
84+
// remove leading slash in full path string
85+
if (fullPath.charAt(0) === "/") {
86+
fullPath = fullPath.substr(1);
87+
}
88+
89+
return fullPath;
90+
}
91+
8892
// Promissory. Guaranteed to read all files in the root of the passed directory.
8993
function getFilesInDirectory(entry, reader, accumEntries, existingPromise) {
9094
var promise = existingPromise || new qq.Promise(),
@@ -304,6 +308,9 @@ qq.DragAndDrop = function(o) {
304308
});
305309
}
306310
});
311+
312+
this._testing = {};
313+
this._testing.extractDirectoryPath = extractDirectoryPath;
307314
};
308315

309316
qq.DragAndDrop.callbacks = function() {

client/js/version.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/*global qq */
2-
qq.version = "5.15.6";
2+
qq.version = "5.15.7";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"title": "Fine Uploader",
44
"main": "lib/traditional.js",
55
"types" : "typescript/fine-uploader.d.ts",
6-
"version": "5.15.6",
6+
"version": "5.15.7",
77
"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.",
88
"keywords": [
99
"amazon",

test/unit/dnd.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,29 @@ describe("drag and drop", function () {
230230
assert(uploadDropZone._testing.isValidFileDrag(ieFileDragEvent), "IE file drag events are valid file drags");
231231
});
232232

233+
it("extracts directory path from entries", function() {
234+
var dnd = new qq.DragAndDrop();
235+
236+
var entry = {
237+
name: "a.txt",
238+
fullPath: "/data/a.txt"
239+
};
240+
241+
var directoryPath = dnd._testing.extractDirectoryPath(entry);
242+
243+
assert.equal(directoryPath, "data/");
244+
});
245+
246+
it("properly extracts directory path when file name occurs in parent directory names", function() {
247+
var dnd = new qq.DragAndDrop();
248+
249+
var entry = {
250+
name: "data",
251+
fullPath: "/data/data"
252+
};
253+
254+
var directoryPath = dnd._testing.extractDirectoryPath(entry);
255+
256+
assert.equal(directoryPath, "data/");
257+
});
233258
});

0 commit comments

Comments
 (0)