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

fix(withoutTrailingSlash): consider qurry param #219

Merged
merged 2 commits into from Mar 15, 2024

Conversation

thijsw
Copy link
Contributor

@thijsw thijsw commented Mar 11, 2024

πŸ”— Linked issue

Fixes #214

❓ 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)

πŸ“ Checklist

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

src/utils.ts Outdated
@@ -84,15 +84,15 @@ export function hasTrailingSlash(
respectQueryAndFragment?: boolean
): boolean {
if (!respectQueryAndFragment) {
return input.endsWith("/");
return !input.includes("?") && input.endsWith("/");
Copy link
Member

Choose a reason for hiding this comment

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

(notice that by default, we do not handle query. we probably don't want to change logic in this line)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i see that query is not handled by default, but what to do with these cases?

because, currently, all these calls return true:

hasTrailingSlash('/a?b=/', false)
hasTrailingSlash('/a/?b=/', false)
hasTrailingSlash('/a?b=/', true)
hasTrailingSlash('/a/?b=/', true)

Copy link
Member

@pi0 pi0 Mar 15, 2024

Choose a reason for hiding this comment

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

Checking, without this change, only failing test is withoutTrailingSlash('foo/?k=/', false /* no respect */). (test in L88 still passes)

Copy link
Member

Choose a reason for hiding this comment

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

I have revert it for now since change on hasProcol like this is risky to introduce behavior changes.

@pi0 pi0 changed the title fix: consider scenario where / is part of query string in withoutTrailingSlash() fix(withoutTrailingSlash): consider qurry param Mar 15, 2024
Copy link

codecov bot commented Mar 15, 2024

Codecov Report

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

Project coverage is 98.69%. Comparing base (d283cf5) to head (2c37ec3).
Report is 30 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #219      +/-   ##
==========================================
+ Coverage   95.27%   98.69%   +3.42%     
==========================================
  Files           7        7              
  Lines         867     1378     +511     
  Branches      187      230      +43     
==========================================
+ Hits          826     1360     +534     
+ Misses         41       18      -23     

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

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 6cd1fcd into unjs:main Mar 15, 2024
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.

withoutTrailingSlash incorrectly strips slash from last query parameter
2 participants