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

Add custom middleware to strip slashes #422

Merged

Conversation

M4tthewDE
Copy link
Contributor

@M4tthewDE M4tthewDE commented Jan 26, 2023

Pull request checklist:

  • CHANGELOG.md was updated, if applicable

Description

Heavily inspired by the middleware provided by chi. The new custom solution also strips url-encoded trailing slashes.
This for example fixes mobile tiktok links ( https://vm.tiktok.com/ZMY8my6vq/ ), which are shared with a trailing slash by default. They didn't match to the link resolver router before the changes in this pr.

EDIT

After some investigation, the true cause for this problem has been found. The middleware from chi uses the decoded URL to strip slashes. So it correctly strips both trailing "/" and trailing "%2F". It then uses the decoded URL to determine the correct handler for the route. Requests to /link_resolver/{url} now contain a URL that is not encoded anymore, and chi fails to find the proper handler. The new middleware fixes this by assigning the encoded URL to the correct parameter.

@codecov
Copy link

codecov bot commented Jan 26, 2023

Codecov Report

Merging #422 (b347edd) into master (7c59cf9) will decrease coverage by 0.10%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master     #422      +/-   ##
==========================================
- Coverage   44.76%   44.66%   -0.10%     
==========================================
  Files         101      101              
  Lines        3731     3739       +8     
==========================================
  Hits         1670     1670              
- Misses       2013     2021       +8     
  Partials       48       48              
Impacted Files Coverage Δ
cmd/api/main.go 0.00% <0.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pajlada pajlada merged commit 1593388 into Chatterino:master Jan 28, 2023
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.

2 participants