Skip to content
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

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

Merged
merged 3 commits into from
Oct 8, 2021

Conversation

jedieaston
Copy link
Contributor

@jedieaston jedieaston commented Oct 8, 2021


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 jedieaston requested a review from a team as a code owner October 8, 2021 15:55
@yao-msft
Copy link
Contributor

yao-msft commented Oct 8, 2021

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@yao-msft yao-msft merged commit 2a14e89 into microsoft:master Oct 8, 2021
@jedieaston jedieaston deleted the CountOutOfRange branch October 8, 2021 23:12
@denelon 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