Skip to content
Merged
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
5 changes: 2 additions & 3 deletions src/wikitextprocessor/parserfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,7 @@ def padright_fn(
"""Implements the padright parser function."""
v = expander(args[0]) if args else ""
cntstr = expander(args[1]).strip() if len(args) >= 2 else "0"
arg2 = expander(args[2]) if len(args) >= 3 and args[2] else "0"
pad = arg2 if len(args) >= 3 and arg2 else "0"
pad = expander(args[2]) if len(args) >= 3 else "0"
if not cntstr.isdigit():
cnt = 0
if cntstr.startswith("-") and cntstr[1:].isdigit():
Expand All @@ -1075,7 +1074,7 @@ def padright_fn(
)
else:
cnt = int(cntstr)
if cnt - len(v) > len(pad):
if cnt - len(v) > len(pad) and len(pad) > 0:
pad = pad * ((cnt - len(v)) // len(pad))
if len(v) < cnt:
v = v + pad[: cnt - len(v)]
Expand Down
5 changes: 5 additions & 0 deletions tests/test_parserfns.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,8 @@ def test_padleft_zero_division(self):
self.wtp.start_page("land")
self.assertEqual(self.wtp.expand("{{padleft:|1|}}"), "")
self.assertEqual(self.wtp.expand("{{padleft:|1}}"), "0")

def test_padright_zero_division(self):
self.wtp.start_page("land")
self.assertEqual(self.wtp.expand("{{padright:|1|}}"), "")
self.assertEqual(self.wtp.expand("{{padright:|1}}"), "0")