From 4ec68cf4ee626621d2e21f720d961918480ee0b4 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 2 Oct 2025 19:47:34 +0000 Subject: [PATCH] [REPL] Do not corrupt input when using numbered_prompt! mode Fix the unbounded possible corruption of the user input by reverting to a non-scoped begin instead of let. ```julia julia> ex = Base.remove_linenums!(:(using A; using B; using C)); REPL.Numbered.get_usings!([], ex) 2-element Vector{Any}: :(using A) :(using C) julia> ex quote using B end ``` --- stdlib/REPL/src/REPL.jl | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/stdlib/REPL/src/REPL.jl b/stdlib/REPL/src/REPL.jl index f2d78071c5642..4fd4989b9ed24 100644 --- a/stdlib/REPL/src/REPL.jl +++ b/stdlib/REPL/src/REPL.jl @@ -1845,25 +1845,10 @@ function repl_eval_counter(hp) end function out_transform(@nospecialize(x), n::Ref{Int}) - return Expr(:toplevel, get_usings!([], x)..., quote - let __temp_val_a72df459 = $x - $capture_result($n, __temp_val_a72df459) - __temp_val_a72df459 - end - end) -end - -function get_usings!(usings, ex) - ex isa Expr || return usings - # get all `using` and `import` statements which are at the top level - for (i, arg) in enumerate(ex.args) - if Base.isexpr(arg, :toplevel) - get_usings!(usings, arg) - elseif Base.isexpr(arg, [:using, :import]) - push!(usings, popat!(ex.args, i)) - end - end - return usings + return Expr(:block, # avoid line numbers or scope that would leak into the output and change the meaning of x + :(local __temp_val_a72df459 = $x), + Expr(:call, capture_result, n, :__temp_val_a72df459), + :__temp_val_a72df459) end function create_global_out!(mod)