Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: ignore queryparams in matching #61

Open
wants to merge 2 commits into
base: v2
Choose a base branch
from

Conversation

kingtimm
Copy link

πŸ”— Linked issue

fixes #54 - inclusion of queryparameters on a path make it fail to match.

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Removed query parameters from the path before it is matched. The router did not seem to support them anyway.

My use-case was in nuxt-vitest's registerEndpoint but found others running into it.

Resolves #54

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Copy link

codecov bot commented Nov 28, 2023

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 95.66%. Comparing base (db3a623) to head (35d94e5).
Report is 10 commits behind head on v2.

Additional details and impacted files
@@            Coverage Diff             @@
##               v2      #61      +/-   ##
==========================================
+ Coverage   95.63%   95.66%   +0.02%     
==========================================
  Files           4        4              
  Lines         435      438       +3     
  Branches       84       84              
==========================================
+ Hits          416      419       +3     
  Misses         19       19              

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@@ -85,6 +85,9 @@ function _matchRoutes(path: string, table: RouteTable): RadixNodeData[] {
// Order should be from less specific to most specific
const matches = [];

// Ignore query parameters
path = path.split("?")[0];
Copy link
Member

Choose a reason for hiding this comment

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

We need to use index check (like https://github.com/unjs/h3/blob/main/src/router.ts#L86) to handle URL like /login?returnTo=/path?foo=bar (context: unjs/h3#190)

@pi0 pi0 changed the title fix: ignore queryparams in matching feat!: ignore queryparams in matching Nov 28, 2023
@pi0
Copy link
Member

pi0 commented Nov 28, 2023

Thanks for PR dear @kingtimm and sorry it is delayed. Main reason is that, the consumer libs (mainly unjs/h3) are already doing this normalization. It is not a breaking-change per-se but doing this means performance overhead of iterating string twice. Because of this i plan this in next major release to be included so we can adjust h3 router behavior while upgrading.

@pi0 pi0 mentioned this pull request Mar 8, 2024
@pi0 pi0 added the v2 label Mar 8, 2024
@pi0 pi0 changed the base branch from main to v2 March 8, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is there a way to ignore query parameters?
2 participants