Handle empty name case when splitting description field in help (#5941)

This commit is contained in:
Jakub Kuczys 2023-06-19 14:15:34 +02:00 committed by GitHub
parent 30dc128c39
commit be5751a7ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -398,9 +398,14 @@ class RedHelpFormatter(HelpFormatterABC):
command_help = command.format_help_for_context(ctx) command_help = command.format_help_for_context(ctx)
if command_help: if command_help:
splitted = command_help.split("\n\n") splitted = filter(None, command_help.split("\n\n"))
name = splitted[0] try:
value = "\n\n".join(splitted[1:]) name = next(splitted)
except StopIteration:
# all parts are empty
pass
else:
value = "\n\n".join(splitted)
if not value: if not value:
value = EMPTY_STRING value = EMPTY_STRING
field = EmbedField(name[:250], value[:1024], False) field = EmbedField(name[:250], value[:1024], False)
@ -571,9 +576,14 @@ class RedHelpFormatter(HelpFormatterABC):
emb["footer"]["text"] = tagline emb["footer"]["text"] = tagline
if description: if description:
splitted = description.split("\n\n") splitted = filter(None, description.split("\n\n"))
name = splitted[0] try:
value = "\n\n".join(splitted[1:]) name = next(splitted)
except StopIteration:
# all parts are empty
pass
else:
value = "\n\n".join(splitted)
if not value: if not value:
value = EMPTY_STRING value = EMPTY_STRING
field = EmbedField(name[:252], value[:1024], False) field = EmbedField(name[:252], value[:1024], False)