Skip to content

Commit

Permalink
fix: don't add unnecessary trailing slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed Nov 30, 2023
1 parent 6c52a59 commit 9d02d50
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deno.lock # this is a deno library
deno.lock
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Or, add it to your deno.json's (or deno.jsonc) tasks:
You can even add a github action:
https://github.com/LeoDog896/deno-outdated/blob/main/.github/workflows/update.yml

Do note that if you're running an application, remove the run action that removes deno.lock `rm deno.lock`, as that is only for libraries
Do note that if you're running an application, remove the run action that
removes deno.lock `rm deno.lock`, as that is only for libraries

## Flags

Expand Down
3 changes: 2 additions & 1 deletion redirect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export async function checkRedirect(url: string): Promise<string | undefined> {
await response.body?.cancel();

if (response.redirected) {
return response.url + (url.endsWith("/") ? "/" : "");
return response.url +
(url.endsWith("/") && !response.url.endsWith("/") ? "/" : "");
} else {
return undefined;
}
Expand Down
6 changes: 6 additions & 0 deletions test/change.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ Deno.test("Slash at the end of a URL isn't removed", async () => {
const source = `https://esm.sh/[email protected]/`; // i-deno-outdated
const result = await findAndReplace(source);

// https://github.com/LeoDog896/deno-outdated/issues/18
assert(
!result.endsWith("//"),
"Result ends with two slashes '//': " + result,
);

assert(
result.endsWith("/"),
"Result doesn't end with '/': " + result,
Expand Down

0 comments on commit 9d02d50

Please sign in to comment.