From 8906fa74cacd6f6cc5d43dd91bfa1b5736906468 Mon Sep 17 00:00:00 2001 From: cobertos Date: Wed, 19 Oct 2022 00:43:56 -0400 Subject: [PATCH] fix: Fix missing leading slash causing extra getDirectoryContents entries --- source/operations/directoryContents.ts | 3 ++- test/node/operations/getDirectoryContents.spec.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/source/operations/directoryContents.ts b/source/operations/directoryContents.ts index 8988e167..1705403b 100644 --- a/source/operations/directoryContents.ts +++ b/source/operations/directoryContents.ts @@ -33,7 +33,8 @@ export async function getDirectoryContents( const response = await request(requestOptions); handleResponseCode(context, response); const davResp = await parseXML(response.data as string); - let files = getDirectoryFiles(davResp, context.remotePath, remotePath, options.details); + const _remotePath = remotePath.startsWith("/") ? remotePath : "/" + remotePath; + let files = getDirectoryFiles(davResp, context.remotePath, _remotePath, options.details); if (options.glob) { files = processGlobFilter(files, options.glob); } diff --git a/test/node/operations/getDirectoryContents.spec.js b/test/node/operations/getDirectoryContents.spec.js index 9ac503c7..7caaa4ea 100644 --- a/test/node/operations/getDirectoryContents.spec.js +++ b/test/node/operations/getDirectoryContents.spec.js @@ -85,6 +85,16 @@ describe("getDirectoryContents", function () { }); }); + it("returns correct results when calling without root slash", function () { + return this.client.getDirectoryContents("sub1").then(function (contents) { + expect(contents).to.have.lengthOf(2); + const sub1 = contents.find(item => item.basename === "irrelephant.jpg"); + expect(sub1).to.be.ok; + const sub2 = contents.find(item => item.basename === "ยากจน #1.txt"); + expect(sub2).to.be.ok; + }); + }); + it("returns correct file results for files with special characters", function () { return this.client.getDirectoryContents("/sub1").then(function (contents) { const sub1 = contents.find(function (item) {