这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@froz42
Copy link
Contributor

@froz42 froz42 commented Jan 23, 2025

This merge request fix issue #713 "Autopatch not working when a prefix is present in the path"

Technical details

I implemented a new function findRelativeRessourcePath in the autopatch package that removes the prefix from the path before searching for the resource in the router by comparing the PUT path and request path.

It will strip the request path until the prefix of the PUT path prefix is found.

It think a better solution could be found if with a proper rework.

I wrote unit tests for the new function.

Fixes #713.

func findRelativeRessourcePath(requestPath string, putPath string) string {
putPathParts := strings.Split(putPath, "/")
// if the path is not deep enough, we return the original path
if len(putPathParts) < 2 {
Copy link
Owner

Choose a reason for hiding this comment

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

What determines this magic number here? Why 2? Are there any cases where this could fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The number 2 is here to handle this case:

if putPath is /{id} -> len(putPathParts == 1 that mean that we don't have a ressource name to find,

A case that could be not covered by this could be:

GET {prefix}/singleRessource
PUT {prefix}/singleRessource

it also protect the table access wantedPrefix := putPathParts[1]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the case that is not supported we just fall back to the default behavior

…e when prefix

That fix a bug that when the path had prefix like "/api" a 404 error occured
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

@codecov
Copy link

codecov bot commented Feb 13, 2025

Codecov Report

Attention: Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.77%. Comparing base (f9ffb6a) to head (2a47997).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
autopatch/autopatch.go 88.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #714      +/-   ##
==========================================
- Coverage   92.79%   92.77%   -0.03%     
==========================================
  Files          22       22              
  Lines        5027     5051      +24     
==========================================
+ Hits         4665     4686      +21     
- Misses        312      314       +2     
- Partials       50       51       +1     

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

@danielgtaylor danielgtaylor merged commit af68f0e into danielgtaylor:main Feb 13, 2025
3 of 5 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.

Autopatch not working when a prefix is present in the path

2 participants