Skip to content

Added validation of count argument for search/list. - #1564

Merged
yao-msft merged 3 commits into
microsoft:masterfrom
jedieaston:CountOutOfRange
Oct 8, 2021
Merged

yao-msft merged 3 commits into
microsoft:masterfrom
jedieaston:CountOutOfRange

Conversation

@jedieaston

@jedieaston Easton Pillay (jedieaston) commented Oct 8, 2021 •

Copy link
Copy Markdown
Contributor

Resolves #1548, #1549.

This PR adds validation to the count argument for the search and list commands, throwing an exception if the value isn't between 1 and 1000 (or if it's out of bounds for an int, since that's what std::stoi converts to). I figured that if the user could handle >1000 results, they could most likely handle all of them, although I can fix this in two seconds if that's too low.

Please let me know if I put anything in the wrong place or if I did something wrong; this looked like an easy enough issue to tackle so I gave it a shot.

Tested manually (please let me know if I need to write unit tests).

Before:

PS C:\Users\easton> winget search 123 -n 853837271271781839344
An unexpected error occurred while executing the command:
stoi argument out of range
PS C:\Users\easton>

After:

PS C:\Users\easton> wingetdev search 123 -n 853837271271781839344
Windows Package Manager v1.0.2
Copyright (c) Microsoft Corporation. All rights reserved.

The requested number of results must be between 1 and 1000. <--- (In red, since it's a CommandException)

Searches for packages from configured sources.

usage: winget search [[-q] <query>] [<options>]

The following arguments are available:
  -q,--query                  The query used to search for a package

The following options are available:
  --id                        Filter results by id
  --name                      Filter results by name
  --moniker                   Filter results by moniker
  --tag                       Filter results by tag
  --command                   Filter results by command
  -s,--source                 Find package using the specified source
  -n,--count                  Show no more than specified number of results (between 1 and 1000).
  -e,--exact                  Find package using exact match
  --header                    Optional Windows-Package-Manager REST source HTTP header
  --accept-source-agreements  Accept all source agreements during source operations

More help can be found at: https://aka.ms/winget-command-search
PS C:\Users\easton>

@jedieaston
Easton Pillay (jedieaston) requested a review from a team as a code owner October 8, 2021 15:55
@yao-msft

yao-msft commented Oct 8, 2021

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@yao-msft
yao-msft merged commit 2a14e89 into microsoft:master Oct 8, 2021
@jedieaston
Easton Pillay (jedieaston) deleted the CountOutOfRange branch October 8, 2021 23:12
@denelon Demitrius Nelon (denelon) linked an issue Oct 11, 2021 that may be closed by this pull request
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.

stoi argument out of range -n allows negative input

2 participants