-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 NuGet Package API for $filter with Id equality #31188
Conversation
Thank you for the fix. Isn't a change like this enough? @@ -96,20 +96,34 @@ func FeedCapabilityResource(ctx *context.Context) {
xmlResponse(ctx, http.StatusOK, Metadata)
}
-var searchTermExtract = regexp.MustCompile(`'([^']+)'`)
+var (
+ searchTermExtract = regexp.MustCompile(`'([^']+)'`)
+ searchTermExact = regexp.MustCompile(`\s+eq\s+'`)
+)
-func getSearchTerm(ctx *context.Context) string {
+func getSearchTerm(ctx *context.Context) packages_model.SearchValue {
searchTerm := strings.Trim(ctx.FormTrim("searchTerm"), "'")
- if searchTerm == "" {
- // $filter contains a query like:
- // (((Id ne null) and substringof('microsoft',tolower(Id)))
- // We don't support these queries, just extract the search term.
- match := searchTermExtract.FindStringSubmatch(ctx.FormTrim("$filter"))
- if len(match) == 2 {
- searchTerm = strings.TrimSpace(match[1])
+ if searchTerm != "" {
+ return packages_model.SearchValue{
+ Value: searchTerm,
+ ExactMatch: false,
+ }
+ }
+
+ // $filter contains a query like:
+ // (((Id ne null) and substringof('microsoft',tolower(Id)))
+ // https://www.odata.org/documentation/odata-version-2-0/uri-conventions/ section 4.5
+ // We don't support these queries, just extract the search term.
+ filter := ctx.FormTrim("$filter")
+ match := searchTermExtract.FindStringSubmatch(filter)
+ if len(match) == 2 {
+ return packages_model.SearchValue{
+ Value: strings.TrimSpace(match[1]),
+ ExactMatch: searchTermExact.MatchString(filter),
}
}
- return searchTerm
+
+ return packages_model.SearchValue{}
}
// https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Protocol/LegacyFeed/V2FeedQueryBuilder.cs
@@ -118,11 +132,9 @@ func SearchServiceV2(ctx *context.Context) {
paginator := db.NewAbsoluteListOptions(skip, take)
pvs, total, err := packages_model.SearchLatestVersions(ctx, &packages_model.PackageSearchOptions{
- OwnerID: ctx.Package.Owner.ID,
- Type: packages_model.TypeNuGet,
- Name: packages_model.SearchValue{
- Value: getSearchTerm(ctx),
- },
+ OwnerID: ctx.Package.Owner.ID,
+ Type: packages_model.TypeNuGet,
+ Name: getSearchTerm(ctx),
IsInternal: optional.Some(false),
Paginator: paginator,
})
@@ -169,10 +181,8 @@ func SearchServiceV2(ctx *context.Context) {
// http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc453752351
func SearchServiceV2Count(ctx *context.Context) {
count, err := nuget_model.CountPackages(ctx, &packages_model.PackageSearchOptions{
- OwnerID: ctx.Package.Owner.ID,
- Name: packages_model.SearchValue{
- Value: getSearchTerm(ctx),
- },
+ OwnerID: ctx.Package.Owner.ID,
+ Name: getSearchTerm(ctx),
IsInternal: optional.Some(false),
})
if err != nil { Could you test if this fixes your choco queries? |
I added the queries choco make with it's commands in the issue here I also tried a
If I removed the edge-case handling of
The tests I added pass so I think it's fine. |
This is cleaner (and correctly fix the / route). With the drawback of not correctly handling "$filter=Id eq ''" queries, so it's ignored in tests.
@KN4CK3R I updated the branch with your implementation suggestion. There is still the edge-case of |
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.
Thank you for the tests.
@KN4CK3R apologies for the ping. Any change this would be backported to 1.22? CONTRIBUTING.md mention that large PRs are not backport, and I don't know how the large qualifier is attributed, but isn't it set due to the changes in tests? |
You can backport it to 1.22 because it's a bug fix. |
Fixes issue when running `choco info pkgname` where `pkgname` is also a substring of another package Id. Relates to go-gitea#31168 --- This might fix the issue linked, but I'd like to test it with more choco commands before closing the issue in case I find other problems if that's ok. --------- Co-authored-by: KN4CK3R <[email protected]>
Should have automatically backported, but ok :) |
Might have misinterpreted KN4CK3R 's message above. |
Everything fine, the Giteabot can create backports too. |
It's preferably if the bot does it, because then we know the content is exactly the same. Manual backport like you did is only when the bot fails to do it because of merge conflict. Let's see if the bot does it now... |
Backport #31188 Fixes issue when running `choco info pkgname` where `pkgname` is also a substring of another package Id. Relates to #31168 --- This might fix the issue linked, but I'd like to test it with more choco commands before closing the issue in case I find other problems if that's ok. I'm pretty inexperienced with Go, so feel free to nitpick things. Not sure I handled [this](https://github.com/tdesveaux/gitea/blob/70f87e11b5caf1ee441ae71c7eba1831f45897d4/routers/api/packages/nuget/nuget.go#L135-L137) in the best way, so looking for feedback on if I should fix the underlying issue (`nil` might be a better default for `Value`?). Co-authored-by: KN4CK3R <[email protected]>
It didn't because of the |
Fixes issue when running `choco info pkgname` where `pkgname` is also a substring of another package Id. Relates to go-gitea#31168 --- This might fix the issue linked, but I'd like to test it with more choco commands before closing the issue in case I find other problems if that's ok. --------- Co-authored-by: KN4CK3R <[email protected]>
* giteaofficial/main: Add `lint-go-gopls` (go-gitea#30729) Make blockquote attention recognize more syntaxes (go-gitea#31240) Fix admin oauth2 custom URL settings (go-gitea#31246) Replace `gt-word-break` with `tw-break-anywhere` (go-gitea#31183) Make pasted "img" tag has the same behavior as markdown image (go-gitea#31235) Remove .segment from .project-column (go-gitea#31204) Fix overflow on push notification (go-gitea#31179) Fix NuGet Package API for $filter with Id equality (go-gitea#31188) Fix overflow on notifications (go-gitea#31178) Update chroma to v2.14.0 (go-gitea#31177) Update air package path (go-gitea#31233) Bump `@github/relative-time-element` to v4.4.1 (go-gitea#31232)
* origin/main: (231 commits) Allow including `Reviewed-on`/`Reviewed-by` lines for custom merge messages (go-gitea#31211) Add `MAX_ROWS` option for CSV rendering (go-gitea#30268) Update `golang.org/x/net` (go-gitea#31260) Add replacement module for `mholt/archiver` (go-gitea#31267) Fix Activity Page Contributors dropdown (go-gitea#31264) Optimize runner-tags layout to enhance visual experience (go-gitea#31258) fix: allow actions artifacts storage migration to complete succesfully (go-gitea#31251) Add `lint-go-gopls` (go-gitea#30729) Make blockquote attention recognize more syntaxes (go-gitea#31240) Fix admin oauth2 custom URL settings (go-gitea#31246) Replace `gt-word-break` with `tw-break-anywhere` (go-gitea#31183) Make pasted "img" tag has the same behavior as markdown image (go-gitea#31235) Remove .segment from .project-column (go-gitea#31204) Fix overflow on push notification (go-gitea#31179) Fix NuGet Package API for $filter with Id equality (go-gitea#31188) Fix overflow on notifications (go-gitea#31178) Update chroma to v2.14.0 (go-gitea#31177) Update air package path (go-gitea#31233) Bump `@github/relative-time-element` to v4.4.1 (go-gitea#31232) Add option for mailer to override mail headers (go-gitea#27860) ...
Fixes issue when running
choco info pkgname
wherepkgname
is also a substring of another package Id.Relates to #31168
This might fix the issue linked, but I'd like to test it with more choco commands before closing the issue in case I find other problems if that's ok.
I'm pretty inexperienced with Go, so feel free to nitpick things.
Not sure I handled this in the best way, so looking for feedback on if I should fix the underlying issue (
nil
might be a better default forValue
?).