Skip to content
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

Fix getDirectoryContents for directories with & in name #213

Merged
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions source/interface/directoryContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,13 @@ function getDirectoryContents(remotePath, options) {
}

function getDirectoryFiles(result, serverBasePath, requestPath, isDetailed = false) {
const remoteTargetPath = pathPosix.join(serverBasePath, requestPath, "/");
const serverBase = pathPosix.join(serverBasePath, "/");
// Extract the response items (directory contents)
const {
multistatus: { response: responseItems }
} = result;
return (
responseItems
// Filter out the item pointing to the current directory (not needed)
.filter(item => {
let href = item.href;
href = pathPosix.join(normalisePath(normaliseHREF(href)), "/");
return href !== serverBase && href !== remoteTargetPath;
})
// Map all items to a consistent output structure (results)
.map(item => {
// HREF is the file path (in full)
Expand All @@ -57,6 +50,14 @@ function getDirectoryFiles(result, serverBasePath, requestPath, isDetailed = fal
serverBase === "/" ? normalisePath(href) : normalisePath(pathPosix.relative(serverBase, href));
return prepareFileFromProps(props, filename, isDetailed);
})
// Filter out the item pointing to the current directory (not needed)
.filter(item =>
item.basename &&
(
item.type === "file" ||
item.filename !== requestPath.replace(/\/$/, "")
)
)
);
}

Expand Down
1 change: 1 addition & 0 deletions test/serverContents/with & in path/file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am content with the contents
7 changes: 7 additions & 0 deletions test/specs/getDirectoryContents.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ describe("getDirectoryContents", function() {
});
});

it('returns only the directory contents for directory with & in name', function() {
return this.client.getDirectoryContents("/with & in path").then(function(contents) {
expect(contents).to.have.lengthOf(1);
expect(contents[0].basename).to.equal("file.txt");
});
});

it("returns correct directory contents when path contains encoded sequences (issue #93)", function() {
return this.client.getDirectoryContents("/two%20words").then(contents => {
expect(contents).to.have.lengthOf(1);
Expand Down