commit 2a14e89d165f1656eedeea51ad2286def92dfac2
parent 123ad7ea3c9fb260264a3cbe4866a58864b0520d
Author: Easton Pillay <easton@planeteaston.com>
Date: Fri, 8 Oct 2021 17:58:32 -0500
Added validation of count argument for search/list. (#1564)
Diffstat:
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/src/AppInstallerCLICore/Command.cpp b/src/AppInstallerCLICore/Command.cpp
@@ -675,6 +675,22 @@ namespace AppInstaller::CLI
throw CommandException(Resource::String::HeaderArgumentNotApplicableWithoutSource, Argument::ForType(Execution::Args::Type::CustomHeader).Name());
}
+ if (execArgs.Contains(Execution::Args::Type::Count))
+ {
+ try
+ {
+ int countRequested = std::stoi(std::string(execArgs.GetArg(Execution::Args::Type::Count)));
+ if (countRequested < 1 || countRequested > 1000)
+ {
+ throw CommandException(Resource::String::CountOutOfBoundsError);
+ }
+ }
+ catch (...)
+ {
+ throw CommandException(Resource::String::CountOutOfBoundsError);
+ }
+ }
+
ValidateArgumentsInternal(execArgs);
}
diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h
@@ -43,6 +43,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(CompleteCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(CompleteCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(CountArgumentDescription);
+ WINGET_DEFINE_RESOURCE_STRINGID(CountOutOfBoundsError);
WINGET_DEFINE_RESOURCE_STRINGID(DisabledByGroupPolicy);
WINGET_DEFINE_RESOURCE_STRINGID(Done);
WINGET_DEFINE_RESOURCE_STRINGID(ExactArgumentDescription);
diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
@@ -167,7 +167,7 @@
<value>Enables context sensitive command line completion</value>
</data>
<data name="CountArgumentDescription" xml:space="preserve">
- <value>Show no more than specified number of results</value>
+ <value>Show no more than specified number of results (between 1 and 1000)</value>
</data>
<data name="Done" xml:space="preserve">
<value>Done</value>
@@ -1190,4 +1190,7 @@ Please specify one of them using the `--source` option to proceed.</value>
<data name="ImportIgnorePackageVersionsArgumentDescription" xml:space="preserve">
<value>Ignore package versions in import file</value>
</data>
-</root>-
\ No newline at end of file
+ <data name="CountOutOfBoundsError" xml:space="preserve">
+ <value>The requested number of results must be between 1 and 1000.</value>
+ </data>
+</root>