Browse Source

client: ImageSearch(): don't send limit if none was specified

The API defines a default limit for searches, but when removing the
default from the cli, the client still sends "0" as a limit, which
is not allowed by existing versions of the API:

    docker search --limit=0 busybox
    Error response from daemon: Limit 0 is outside the range of [1, 100]

This patch changes the client so that no limit is sent if none was set ("0"),
allowing the daemon to use its (or the registry's) default.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 3 years ago
parent
commit
8ba83f63a0
1 changed files with 4 additions and 2 deletions
  1. 4 2
      client/image_search.go

+ 4 - 2
client/image_search.go

@@ -3,8 +3,8 @@ package client // import "github.com/docker/docker/client"
 import (
 import (
 	"context"
 	"context"
 	"encoding/json"
 	"encoding/json"
-	"fmt"
 	"net/url"
 	"net/url"
+	"strconv"
 
 
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types"
 	"github.com/docker/docker/api/types/filters"
 	"github.com/docker/docker/api/types/filters"
@@ -18,7 +18,9 @@ func (cli *Client) ImageSearch(ctx context.Context, term string, options types.I
 	var results []registry.SearchResult
 	var results []registry.SearchResult
 	query := url.Values{}
 	query := url.Values{}
 	query.Set("term", term)
 	query.Set("term", term)
-	query.Set("limit", fmt.Sprintf("%d", options.Limit))
+	if options.Limit > 0 {
+		query.Set("limit", strconv.Itoa(options.Limit))
+	}
 
 
 	if options.Filters.Len() > 0 {
 	if options.Filters.Len() > 0 {
 		filterJSON, err := filters.ToJSON(options.Filters)
 		filterJSON, err := filters.ToJSON(options.Filters)