diff --git a/source/tools/dav.ts b/source/tools/dav.ts index 77bf395..69aae0f 100644 --- a/source/tools/dav.ts +++ b/source/tools/dav.ts @@ -23,11 +23,22 @@ enum PropertyType { function getParser(): XMLParser { return new XMLParser({ + allowBooleanAttributes: true, + attributeNamePrefix: "", + textNodeName: "text", + ignoreAttributes: false, removeNSPrefix: true, numberParseOptions: { hex: true, leadingZeros: false }, + attributeValueProcessor(attrName, attrValue, jPath) { + // handle boolean attributes + if (attrValue === "true" || attrValue === "false") { + return attrValue === "true"; + } + return attrValue; + }, tagValueProcessor(tagName, tagValue, jPath) { if (jPath.endsWith("propstat.prop.displayname")) { // Do not parse the display name, because this causes e.g. '2024.10' to result in number 2024.1 diff --git a/test/node/operations/stat.spec.ts b/test/node/operations/stat.spec.ts index a78bc03..52a80b3 100644 --- a/test/node/operations/stat.spec.ts +++ b/test/node/operations/stat.spec.ts @@ -130,6 +130,38 @@ describe("stat", function () { }); }); + it("correctly parses the attributes property", async function () { + returnFakeResponse( + readFileSync( + new URL("../../responses/propfind-attributes.xml", import.meta.url) + ).toString() + ); + + await this.client.stat("/foo/", { details: true }).then(function (result) { + expect(result.data).to.have.property("props").that.is.an("object"); + expect(result.data.props).to.have.property("system-tags").that.is.an("object"); + expect(result.data.props["system-tags"]["system-tag"]) + .to.be.an("array") + .and.have.lengthOf(2); + // Tag1 + // Tag2 + expect(result.data.props["system-tags"]["system-tag"]).to.deep.equal([ + { + "can-assign": true, + id: "321", + checked: true, + text: "Tag1" + }, + { + "can-assign": false, + id: "654", + prop: "", + text: "Tag2" + } + ]); + }); + }); + describe("with details: true", function () { it("returns data property", function () { return this.client.stat("/", { details: true }).then(function (result) { diff --git a/test/responses/propfind-attributes.xml b/test/responses/propfind-attributes.xml new file mode 100644 index 0000000..4848d08 --- /dev/null +++ b/test/responses/propfind-attributes.xml @@ -0,0 +1,27 @@ + + + + /remote.php/dav/files/admin/foo/ + + + "66a15a0171527" + Wed, 24 Jul 2024 19:46:09 GMT + 1970-01-01T00:00:00+00:00 + + Tag1 + Tag2 + + + HTTP/1.1 200 OK + + + + + + + HTTP/1.1 404 Not Found + + +