-
Notifications
You must be signed in to change notification settings - Fork 385
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(gnoweb): simplify url parsing system #3366
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Signed-off-by: gfanton <[email protected]>
Codecov ReportAttention: Patch coverage is
📢 Thoughts on this report? Let us know! |
Signed-off-by: gfanton <[email protected]>
Should we update the breadcrumb (to add the query path) in the same PR? |
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
Signed-off-by: gfanton <[email protected]>
@alexiscolin I will do this in another PR ;) |
default: | ||
return nil, fmt.Errorf("%w: %s", ErrURLMalformedPath, u.Path) | ||
} | ||
if !rePkgOrRealmPath.MatchString(upath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we used gnolang.IsPurePackagePath
/ gnolang.IsRealmPath
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To check the string path directly? Or do you mean removing the check and using IsPurePackagePath
and IsRealmPath
? I would like to have IsPurePackagePath
and IsRealmPath
; I think it's a better idea than Kind()
, but I'm not sure why you pointed out this specific line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just had beef with this regex and this seemed a good place where to make a comment :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But yeah, I think we can also substitute this regex to determine if it's a valid path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should forbid a URL that is neither pure nor a realm. I prefer this package to perform minimal checks; it should be the caller's choice to accept the URL based on the parsed information. That said, we can still establish a minimal base to work on without assuming any urls.
What do you think about:
- Removing the concept of "kind" within the structure while still providing helpers to check if the method is pure or a realm, as you mentioned.
- Adding a new
File
field, trimming any file from the path when parsing and adding it to the structure. - Refining the regex to define what a path can be, based on what we have in gnovm/pkg/gnolang/helpers.go, with the only base constraint that it must start with a slash and at least one character. This will makes the check and the assumption of the path structure simple and easy to manage.
var rePkgOrRealmPath = regexp.MustCompile(`^/[a-z][a-z0-9_./]*$`)
Only pure and realm exist, but gnoweb
will likely extend this with /u
, for example. So it makes sense to me to make GnoURL
a bit more flexible in what it can parse. This way, the caller can decide whether to use it as a direct call to the node or to redirect the user to something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thehowl suggestion preview: gfanton@d0eb4b0
I've directly pushed the commit 8f93987 with suggested changes. If you think it's appropriate, feel free to merge it. Otherwise, please don't hesitate to give me feedback so I can make the necessary updates.
edit: i've made another commit (62b005a) to handle special file, such as LICSENSE
Co-authored-by: Morgan <[email protected]>
- Removing the concept of "kind" within the structure while still providing helpers to check if the method is pure or a realm: - Adding a new File field, trimming any file from the path when parsing and adding it to the structure. - Refining the regex to define what a path can be, based on what we have in `gnovm/pkg/gnolang/helpers.go` "var rePkgOrRealmPath = regexp.MustCompile(`^/[a-z][a-z0-9_/]*$`)" Signed-off-by: gfanton <[email protected]>
8d51e3b
to
8f93987
Compare
Signed-off-by: gfanton <[email protected]>
c6e36df
to
62b005a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 💯
Feel free to merge 🚀
@@ -125,7 +126,7 @@ func TestAnalytics(t *testing.T) { | |||
request := httptest.NewRequest(http.MethodGet, route, nil) | |||
response := httptest.NewRecorder() | |||
router.ServeHTTP(response, request) | |||
fmt.Println("HELLO:", response.Body.String()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
// but this may require changes in some realms. | ||
args := gnoURL.Args | ||
if !encodeFlags.Has(EncodeNoEscape) { | ||
args = escapeDollarSign(url.PathEscape(args)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: you only call this func once
} | ||
|
||
func (url GnoURL) EncodePath() string { | ||
// Encode encodes the URL components based on the provided flags. | ||
func (gnoURL GnoURL) Encode(encodeFlags EncodeFlag) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about adding a small section on the gnoweb
docs for these URL flags?
This PR simplifies the URL parsing system:
regexp
that was introduced in thegnoweb
revamp.GnoURL
.Encode
method more composable to adapt to various use cases.