Skip to content

fix(utils): handle raw hashes and queries in url relative() + add tests#770

Open
ryzrr wants to merge 1 commit intonodejs:mainfrom
ryzrr:fix-url-relative-shortcircuit
Open

fix(utils): handle raw hashes and queries in url relative() + add tests#770
ryzrr wants to merge 1 commit intonodejs:mainfrom
ryzrr:fix-url-relative-shortcircuit

Conversation

@ryzrr
Copy link
Copy Markdown
Contributor

@ryzrr ryzrr commented Apr 14, 2026

Description
This PR adds the missing unit tests for the relative utility in src/utils/url.mjs and patches a minor logic flaw in how it handles hashes and query strings. I included a quick short-circuit to ensure that raw fragments (like #fragment) stay completely intact instead of being mistakenly processed as directory paths.

Note: This is not actively breaking the site right now because no component
currently passes a raw hash to the resolver. However, it is a dormant footgun
that could easily cause unexpected bugs if routing or navigation changes in the future.
*

Validation
I ran the Node test suite locally to verify the new url.test.mjs file. The tests confirm that all URL resolution edge cases are handled perfectly and that the existing logic remains completely untouched.

Related Issues
No Related Issues.

Check List

  • I have read the Contributing Guidelines and made commit messages that follow the guideline.
  • I have run node --run test and all tests passed.
  • I have check code formatting with node --run format & node --run lint.
  • I've covered new added functionality with unit tests if necessary.

@ryzrr ryzrr requested a review from a team as a code owner April 14, 2026 18:31
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
api-docs-tooling Ready Ready Preview Apr 14, 2026 6:32pm

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 14, 2026

PR Summary

Low Risk
Low risk: small, well-scoped change to URL path handling plus new unit coverage; main impact is link generation if any callers pass raw fragments/queries.

Overview
Fixes src/utils/url.mjs relative() to short-circuit and return inputs that start with # or ?, preventing fragments/queries from being treated as path segments.

Adds a new url.test.mjs suite covering protocol URLs, raw fragments/queries, and several relative-path resolution cases (including anchors).

Reviewed by Cursor Bugbot for commit 5f013f9. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.56%. Comparing base (3d00fa8) to head (5f013f9).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #770      +/-   ##
==========================================
+ Coverage   78.43%   78.56%   +0.13%     
==========================================
  Files         157      158       +1     
  Lines       13962    14015      +53     
  Branches     1152     1163      +11     
==========================================
+ Hits        10951    11011      +60     
+ Misses       3006     3000       -6     
+ Partials        5        4       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant