Skip to content

Commit daf64d0

Browse files
authored
Merge pull request #385 from tatuylonen/padright
Also apply changes in parser function `padleft` to `padright`
2 parents e76a68a + 4344af9 commit daf64d0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/wikitextprocessor/parserfns.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,8 +1062,7 @@ def padright_fn(
10621062
"""Implements the padright parser function."""
10631063
v = expander(args[0]) if args else ""
10641064
cntstr = expander(args[1]).strip() if len(args) >= 2 else "0"
1065-
arg2 = expander(args[2]) if len(args) >= 3 and args[2] else "0"
1066-
pad = arg2 if len(args) >= 3 and arg2 else "0"
1065+
pad = expander(args[2]) if len(args) >= 3 else "0"
10671066
if not cntstr.isdigit():
10681067
cnt = 0
10691068
if cntstr.startswith("-") and cntstr[1:].isdigit():
@@ -1075,7 +1074,7 @@ def padright_fn(
10751074
)
10761075
else:
10771076
cnt = int(cntstr)
1078-
if cnt - len(v) > len(pad):
1077+
if cnt - len(v) > len(pad) and len(pad) > 0:
10791078
pad = pad * ((cnt - len(v)) // len(pad))
10801079
if len(v) < cnt:
10811080
v = v + pad[: cnt - len(v)]

tests/test_parserfns.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,8 @@ def test_padleft_zero_division(self):
214214
self.wtp.start_page("land")
215215
self.assertEqual(self.wtp.expand("{{padleft:|1|}}"), "")
216216
self.assertEqual(self.wtp.expand("{{padleft:|1}}"), "0")
217+
218+
def test_padright_zero_division(self):
219+
self.wtp.start_page("land")
220+
self.assertEqual(self.wtp.expand("{{padright:|1|}}"), "")
221+
self.assertEqual(self.wtp.expand("{{padright:|1}}"), "0")

0 commit comments

Comments
 (0)