Skip to content

Commit

Permalink
Merge pull request #384 from susnux/fix/displayname
Browse files Browse the repository at this point in the history
fix: Ensure that the `displayname` property is not parsed
  • Loading branch information
perry-mitchell authored Sep 7, 2024
2 parents 71ecdff + 1932689 commit 7a9884a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions source/tools/dav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ function getParser(): XMLParser {
numberParseOptions: {
hex: true,
leadingZeros: false
},
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
return;
}
return tagValue;
}
// We don't use the processors here as decoding is done manually
// later on - decoding early would break some path checks.
Expand Down
15 changes: 15 additions & 0 deletions test/node/tools/dav.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect } from "chai";
import { readFile } from "fs/promises";
import { parseXML } from "../../../source/index.js";

describe("parseXML", function () {
it("keeps numeric-looking displaynames", async function () {
const data = await readFile(
new URL("../../responses/propfind-float-like-displayname.xml", import.meta.url)
);
const parsed = await parseXML(data.toString());
expect(parsed.multistatus.response).to.have.length(1);
// Ensure trailing zero is not lost
expect(parsed.multistatus.response[0].propstat.prop.displayname).to.equal("2024.10");
});
});
27 changes: 27 additions & 0 deletions test/responses/propfind-float-like-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>2024.10</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 7a9884a

Please sign in to comment.