File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -1037,7 +1037,7 @@ def padleft_fn(
1037
1037
"""Implements the padleft parser function."""
1038
1038
v = expander (args [0 ]) if args else ""
1039
1039
cntstr = expander (args [1 ]).strip () if len (args ) >= 2 else "0"
1040
- pad = expander (args [2 ]) if len (args ) >= 3 and args [ 2 ] else "0"
1040
+ pad = expander (args [2 ]) if len (args ) >= 3 else "0"
1041
1041
if not cntstr .isdigit ():
1042
1042
if cntstr .startswith ("-" ) and cntstr [1 :].isdigit ():
1043
1043
pass
@@ -1049,7 +1049,7 @@ def padleft_fn(
1049
1049
cnt = 0
1050
1050
else :
1051
1051
cnt = int (cntstr )
1052
- if cnt - len (v ) > len (pad ):
1052
+ if cnt - len (v ) > len (pad ) and len ( pad ) > 0 :
1053
1053
pad = pad * ((cnt - len (v )) // len (pad ))
1054
1054
if len (v ) < cnt :
1055
1055
v = pad [: cnt - len (v )] + v
Original file line number Diff line number Diff line change @@ -207,3 +207,10 @@ def test_int(self):
207
207
self .wtp .project = "wikipedia"
208
208
self .assertEqual (self .wtp .expand ("{{int:lang}}" ), "⧼lang⧽" )
209
209
self .assertEqual (self .wtp .expand ("{{int:}}" ), "[[:Template:int:]]" )
210
+
211
+ def test_padleft_zero_division (self ):
212
+ # https://en.wiktionary.org/wiki/land
213
+ # https://en.wiktionary.org/wiki/Template:R:osx:Kobler
214
+ self .wtp .start_page ("land" )
215
+ self .assertEqual (self .wtp .expand ("{{padleft:|1|}}" ), "" )
216
+ self .assertEqual (self .wtp .expand ("{{padleft:|1}}" ), "0" )
You can’t perform that action at this time.
0 commit comments