( WIP ) fix(urls): preserve trailing slashes and normalize URL joining
#18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR resolves three issues related to URL handling:
🛠 1. Preserve trailing slash in path components
When splitting URL paths, trailing slashes were previously lost — leading to loss of semantic distinction between endpoints like
/adminand/admin/. These can represent different resources (e.g. route vs. directory), so we now preserve the trailing slash on the last component if it existed in the original path.Commit:
🔧 2. Normalize base URL and word joining
Incorrect handling of slashes between a base URL and a word (e.g.
/admin+login) could result in malformed URLs like/adminloginor/admin//login. This change trims the trailing slash from the base and the leading slash from the word before joining them with a single slash.Commit:
🚫 3. Avoid duplicate handling of the same URL in recursive mode
In recursive mode, the same URL could be inserted and handled multiple times. This introduces a check to avoid redundant processing and handler calls.
Commit:
✅ Result
/admin+login→/admin/login/admin/+login→/admin/login/admin+/login→/admin/login/admin/+/login→/admin/login/admin/path will now be stored as["admin/"]/adminpath will now be stored as["admin"]This preserves semantic meaning, improves correctness when mapping URL paths and constructing tasks, and prevents unnecessary re-processing.
🧪 Test Coverage
Tested manually with paths:
/install//install/api//api/v1//api/v1Confirmed correct insertion, dispatch, and uniqueness under recursion.