Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions awscli/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ def add_to_parser(self, parser):
cli_name = self.cli_name
parser.add_argument(
cli_name,
help=self.documentation,
help=self.documentation.replace('%', '%%'),
type=self.cli_type,
required=self.required,
)
Expand Down Expand Up @@ -600,7 +600,7 @@ def add_to_arg_table(self, argument_table):
def add_to_parser(self, parser):
parser.add_argument(
self.cli_name,
help=self.documentation,
help=self.documentation.replace('%', '%%'),
action=self._action,
default=self._default,
dest=self._destination,
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/test_argprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from awscli.help import OperationHelpCommand
from awscli.paramfile import LOCAL_PREFIX_MAP, URIArgumentHandler
from awscli.testutils import BaseCLIDriverTest, mock, temporary_file, unittest
from awscli.argparser import ArgTableArgParser


# These tests use real service types so that we can
Expand Down Expand Up @@ -968,5 +969,39 @@ def test_json_value_decode_error(self):
unpack_cli_arg(self.p, value)


class TestArgumentPercentEscaping(BaseArgProcessTest):
def _test_percent_escaping(self, arg_type, arg_class, doc_string):
argument = self.create_argument(
{
'Test': {
'type': arg_type,
'documentation': doc_string,
}
}
)
arg = arg_class(
'test-arg',
argument.argument_model.members['Test'],
mock.Mock(),
mock.Mock(),
is_required=False,
)
arg_table = {arg.name: arg}
parser = ArgTableArgParser(arg_table)
help_output = parser.format_help()
self.assertIn(doc_string, help_output)

def test_cli_argument_escapes_percent(self):
self._test_percent_escaping('string', CLIArgument, 'Symbols: % ^ & *')

def test_boolean_argument_escapes_percent(self):
self._test_percent_escaping('boolean', BooleanArgument, 'Symbols: % ^ & *')

def test_cli_argument_escapes_url_encoded_percent(self):
self._test_percent_escaping('string', CLIArgument, 'File: test%28file%29.png')

def test_boolean_argument_escapes_url_encoded_percent(self):
self._test_percent_escaping('boolean', BooleanArgument, 'File: test%28file%29.png')

if __name__ == '__main__':
unittest.main()