Skip to content

Commit

Permalink
Merge pull request #704 from dethell-jh/issue-703-handle-endpoint-wit…
Browse files Browse the repository at this point in the history
…h-trailing-slash
  • Loading branch information
pmcelhaney committed Jan 6, 2024
2 parents 3a55b66 + 0614f20 commit c037285
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/selfish-cameras-wave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"counterfact": patch
---

Fix issue 703: Endpoint with trailing slash
5 changes: 4 additions & 1 deletion src/server/module-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ export class ModuleTree {
);
}

if (remainingSegments.length === 0) {
if (
remainingSegments.length === 0 ||
(remainingSegments.length === 1 && remainingSegments[0] === "")
) {
return this.buildMatch(directory, segment, pathVariables, matchedPath);
}

Expand Down
6 changes: 6 additions & 0 deletions test/server/module-tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ it("finds a file under a subdirectory", () => {
expect(match(moduleTree, "/a/b")).toBe("b");
});

it("finds a file with a trailing slash in the path", () => {
const moduleTree = new ModuleTree();
add(moduleTree, "/a", "a");
expect(match(moduleTree, "/a/")).toBe("a");
});

it("finds a file with a wildcard match", () => {
const moduleTree = new ModuleTree();
add(moduleTree, "/a", "a");
Expand Down

0 comments on commit c037285

Please sign in to comment.