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(
10371037 """Implements the padleft parser function."""
10381038 v = expander (args [0 ]) if args else ""
10391039 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"
10411041 if not cntstr .isdigit ():
10421042 if cntstr .startswith ("-" ) and cntstr [1 :].isdigit ():
10431043 pass
@@ -1049,7 +1049,7 @@ def padleft_fn(
10491049 cnt = 0
10501050 else :
10511051 cnt = int (cntstr )
1052- if cnt - len (v ) > len (pad ):
1052+ if cnt - len (v ) > len (pad ) and len ( pad ) > 0 :
10531053 pad = pad * ((cnt - len (v )) // len (pad ))
10541054 if len (v ) < cnt :
10551055 v = pad [: cnt - len (v )] + v
Original file line number Diff line number Diff line change @@ -207,3 +207,10 @@ def test_int(self):
207207 self .wtp .project = "wikipedia"
208208 self .assertEqual (self .wtp .expand ("{{int:lang}}" ), "⧼lang⧽" )
209209 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