Skip to content

fix: preserve trailing slash in joinURL when path is "/" (#134)#137

Open
SAY-5 wants to merge 1 commit into
unjs:mainfrom
SAY-5:fix/joinurl-preserve-root-slash-134
Open

fix: preserve trailing slash in joinURL when path is "/" (#134)#137
SAY-5 wants to merge 1 commit into
unjs:mainfrom
SAY-5:fix/joinurl-preserve-root-slash-134

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented May 13, 2026

Closes #134. The path === "/" early-return dropped the slash so joinURL("/maildev", "/") returned "/maildev" instead of "/maildev/", causing redirect loops with sub-path-mounted upstreams. Treat root-path as a real path and let the trailing/leading slash logic produce the correct join. Per @pi0 in #134 ("PR welcome!").

Summary by CodeRabbit

  • Bug Fixes

    • Fixed URL path joining to correctly preserve single trailing slashes in certain cases.
  • Tests

    • Added tests to verify trailing-slash handling in URL path operations.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0c3cd289-29e3-4bd9-bfad-57a423ec690f

📥 Commits

Reviewing files that changed from the base of the PR and between 9dc2425 and 79703f8.

📒 Files selected for processing (2)
  • src/_utils.ts
  • test/_utils.test.ts

📝 Walkthrough

Walkthrough

The joinURL function is refined to handle trailing slashes more precisely. Previously, the function treated both falsy path and path === "/" as early-return cases; now only falsy path triggers early return, allowing "/" to be joined normally. Two test cases verify the behavior for both a standalone "/" path and the case where both base and path end with "/".

Changes

Trailing slash handling in joinURL

Layer / File(s) Summary
joinURL trailing slash logic and validation
src/_utils.ts, test/_utils.test.ts
The early-return condition in joinURL is narrowed to only trigger on falsy path, allowing path === "/" to proceed through normal joining logic. Two new test cases validate that "/" paths are joined correctly and that multiple trailing slashes are collapsed to a single slash.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related issues

Poem

🐰 A slash was treated like a ghost,
But now it joins the joining post.
With logic refined, the path flows true,
Single slashes shine right through! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately describes the main change: fixing joinURL to preserve trailing slashes when the path is "/". It directly addresses the core issue and aligns perfectly with the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

joinURL drops trailing slash when path is "/", breaks proxying to apps mounted on a sub-path

1 participant