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: Ensure that the displayname property is not parsed #384

Merged
merged 1 commit into from
Sep 7, 2024
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
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>
Loading