Skip to content

Commit

Permalink
Merge pull request #380 from susnux/fix/displayname-type
Browse files Browse the repository at this point in the history
fix(dav): The `displayname` prop should always be a string
  • Loading branch information
perry-mitchell authored Aug 2, 2024
2 parents b3272b2 + 19e2a0d commit e48fa0f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
4 changes: 4 additions & 0 deletions source/tools/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ export function prepareFileFromProps(
stat.mime = mimeType && typeof mimeType === "string" ? mimeType.split(";")[0] : "";
}
if (isDetailed) {
// The XML parser tries to interpret values, but the display name is required to be a string
if (typeof props.displayname !== "undefined") {
props.displayname = String(props.displayname);
}
stat.props = props;
}
return stat;
Expand Down
16 changes: 16 additions & 0 deletions test/node/operations/getDirectoryContents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ describe("getDirectoryContents", function () {
});
});

it("correctly parses the displayname property", function () {
returnFakeResponse(
readFileSync(
new URL("../../responses/propfind-numeric-displayname.xml", import.meta.url)
).toString()
);
return this.client.getDirectoryContents("/1", { details: true }).then(function (result) {
expect(result.data).to.have.length(1);
expect(result.data[0]).to.have.property("props").that.is.an("object");
expect(result.data[0].props)
.to.have.property("displayname")
.that.is.a("string")
.and.equal("1");
});
});

it("returns the contents of a directory with repetitive naming", function () {
return this.client.getDirectoryContents("/webdav/server").then(function (contents) {
expect(contents).to.be.an("array");
Expand Down
20 changes: 19 additions & 1 deletion test/node/operations/stat.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from "chai";
import { readFileSync } from "fs";
import { WebDAVClientError } from "../../../source/types.js";
import {
SERVER_PASSWORD,
Expand All @@ -8,7 +9,8 @@ import {
createWebDAVClient,
createWebDAVServer,
useCustomXmlResponse,
restoreRequests
restoreRequests,
returnFakeResponse
} from "../../helpers.node.js";

describe("stat", function () {
Expand Down Expand Up @@ -112,6 +114,22 @@ describe("stat", function () {
});
});

it("correctly parses the displayname property", function () {
returnFakeResponse(
readFileSync(
new URL("../../responses/propfind-numeric-displayname.xml", import.meta.url)
).toString()
);

this.client.stat("/1/", { details: true }).then(function (result) {
expect(result.data).to.have.property("props").that.is.an("object");
expect(result.data.props)
.to.have.property("displayname")
.that.is.a("string")
.and.equal("1");
});
});

describe("with details: true", function () {
it("returns data property", function () {
return this.client.stat("/", { details: true }).then(function (result) {
Expand Down
27 changes: 27 additions & 0 deletions test/responses/propfind-numeric-displayname.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<d:multistatus
xmlns:d="DAV:">
<d:response>
<d:href>/remote.php/dav/files/admin/1/</d:href>
<d:propstat>
<d:prop>
<d:getetag>&quot;66a15a0171527&quot;</d:getetag>
<d:getlastmodified>Wed, 24 Jul 2024 19:46:09 GMT</d:getlastmodified>
<d:creationdate>1970-01-01T00:00:00+00:00</d:creationdate>
<d:displayname>1</d:displayname>
<d:quota-available-bytes>-3</d:quota-available-bytes>
<d:resourcetype>
<d:collection/>
</d:resourcetype>
</d:prop>
<d:status>HTTP/1.1 200 OK</d:status>
</d:propstat>
<d:propstat>
<d:prop>
<d:getcontentlength/>
<d:getcontenttype/>
</d:prop>
<d:status>HTTP/1.1 404 Not Found</d:status>
</d:propstat>
</d:response>
</d:multistatus>

0 comments on commit e48fa0f

Please sign in to comment.