Skip to content

fix(withBase, withoutBase): prevent false prefix matches#313

Merged
pi0 merged 3 commits intounjs:mainfrom
Flo0806:fix/withoutbase-false-prefix-match
Jan 14, 2026
Merged

fix(withBase, withoutBase): prevent false prefix matches#313
pi0 merged 3 commits intounjs:mainfrom
Flo0806:fix/withoutbase-false-prefix-match

Conversation

@Flo0806
Copy link
Contributor

@Flo0806 Flo0806 commented Jan 11, 2026

Resolves: nuxt/nuxt#33924

Summary

While investigating nuxt/nuxt#33924, I found that withoutBase was being a bit too eager when stripping base URLs.

The issue: When using baseURL: '/admin/' with a page like /admin-dashboard, the function incorrectly stripped /admin because it only checked startsWith() without verifying that the match ends at a path segment boundary.

withoutBase("/admin-dashboard", "/admin/")
// Before: "/-dashboard" ❌
// After:  "/admin-dashboard" ✅

The fix: Added a simple check to ensure the character after the base is either /, ?, or end of string before treating it as a valid base match.

Test plan

  • Added test cases for the bug
  • All existing tests pass

Update ⚠️

Same issue is in withBase as well. I also fixed it and added new tests.

@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.82%. Comparing base (d283cf5) to head (cb6af4e).
⚠️ Report is 96 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #313      +/-   ##
==========================================
+ Coverage   95.27%   96.82%   +1.55%     
==========================================
  Files           7        6       -1     
  Lines         867      472     -395     
  Branches      187      155      -32     
==========================================
- Hits          826      457     -369     
+ Misses         41       14      -27     
- Partials        0        1       +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pi0 pi0 changed the title fix(withoutBase): prevent false prefix matches fix(withBase, withoutBase): prevent false prefix matches Jan 14, 2026
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ❤️

@pi0 pi0 merged commit eb29945 into unjs:main Jan 14, 2026
4 checks passed
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.

Nuxt Links not being handled properly in Nuxt Generate

2 participants