Skip to content

Commit 01ebd93

Browse files
authored
fix some invalidations in rpad/lpad (#37606)
1 parent 3427b00 commit 01ebd93

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

base/strings/util.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,15 @@ julia> lpad("March", 10)
304304
" March"
305305
```
306306
"""
307-
lpad(s, n::Integer, p::Union{AbstractChar,AbstractString}=' ') = lpad(string(s), n, string(p))
307+
lpad(s, n::Integer, p::Union{AbstractChar,AbstractString}=' ') = lpad(string(s)::AbstractString, n, string(p))
308308

309309
function lpad(
310310
s::Union{AbstractChar,AbstractString},
311311
n::Integer,
312312
p::Union{AbstractChar,AbstractString}=' ',
313313
) :: String
314-
m = signed(n) - length(s)
314+
n = Int(n)::Int
315+
m = signed(n) - Int(length(s))::Int
315316
m 0 && return string(s)
316317
l = length(p)
317318
q, r = divrem(m, l)
@@ -331,14 +332,15 @@ julia> rpad("March", 20)
331332
"March "
332333
```
333334
"""
334-
rpad(s, n::Integer, p::Union{AbstractChar,AbstractString}=' ') = rpad(string(s), n, string(p))
335+
rpad(s, n::Integer, p::Union{AbstractChar,AbstractString}=' ') = rpad(string(s)::AbstractString, n, string(p))
335336

336337
function rpad(
337338
s::Union{AbstractChar,AbstractString},
338339
n::Integer,
339340
p::Union{AbstractChar,AbstractString}=' ',
340341
) :: String
341-
m = signed(n) - length(s)
342+
n = Int(n)::Int
343+
m = signed(n) - Int(length(s))::Int
342344
m 0 && return string(s)
343345
l = length(p)
344346
q, r = divrem(m, l)

0 commit comments

Comments
 (0)