mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-11-14 00:07:00 +01:00
fix: count dollar-prefixed directories as literal paths
This commit is contained in:
1 parent
d4b9fd85e7
commit
7ffbfd09d7
2 files changed
+8
-1
No files matched your search
@@ -30,7 +30,7 @@ export async function folderCounts(repo: Repository, requestedPath: unknown): Pr
|
||||
...(originalPath ? { $or: [{ path: originalPath }, { path: { $regex: "^" + escapedPrefix } }] } : {}),
|
||||
} },
|
||||
{ $project: { child: { $cond: [
|
||||
{ $eq: ["$path", originalPath] }, "",
|
||||
{ $eq: ["$path", { $literal: originalPath }] }, "",
|
||||
{ $arrayElemAt: [{ $split: [{ $substrCP: ["$path", prefixLength,
|
||||
{ $subtract: [{ $strLenCP: "$path" }, prefixLength] }] }, "/"] }, 0] },
|
||||
] } } },
|
||||
|
||||
@@ -66,6 +66,13 @@ describe("folder count request validation", () => {
|
||||
expect(JSON.stringify(scoped)).not.to.match(/Alice|Bob/);
|
||||
});
|
||||
|
||||
for (const name of ["$data", "$$ROOT", "$$CURRENT"]) it(`treats directory ${name} as a literal in aggregation expressions`, async () => {
|
||||
await insert([{ name, path: "" }, { name: "direct.txt", path: name, size: 1 },
|
||||
{ name: "$nested", path: name }, { name: "child.txt", path: `${name}/$nested`, size: 1 }]);
|
||||
expect(await folderCounts(repo, name)).to.deep.equal({ [name]: 2, [`${name}/$nested`]: 1 });
|
||||
expect(await folderCounts(repo, `${name}/$nested`)).to.deep.equal({ [`${name}/$nested`]: 1 });
|
||||
});
|
||||
|
||||
it("uses the active generation on each request without reusing obsolete counts", async () => {
|
||||
await insert([{ path: "old", name: "a", size: 1 }]);
|
||||
expect(await folderCounts(repo, "")).to.deep.equal({ "": 1, old: 1 });
|
||||
|
||||
Reference in new issue
Block a user