mirror of
https://github.com/skywind3000/z.lua
synced 2026-03-13 11:19:50 +00:00
Fix leaked pushd.
`z somedir` uses double `pushd` to tunnel the new path out past the endlocal that restores the environment state. But it ended up leaving a pushd on the dir stack. This change exploits normal variable expansion to restore the dir stack to its initial state while still successfully tunneling the new path out past the endlocal.
This commit is contained in:
11
z.cmd
11
z.cmd
@@ -106,7 +106,7 @@ if /i "%RunMode%"=="-n" (
|
||||
pushd !NewPath!
|
||||
pushd !NewPath!
|
||||
endlocal
|
||||
popd
|
||||
goto popdir
|
||||
)
|
||||
)
|
||||
) else (
|
||||
@@ -115,4 +115,13 @@ if /i "%RunMode%"=="-n" (
|
||||
|
||||
:end
|
||||
echo.
|
||||
goto :eof
|
||||
|
||||
:popdir
|
||||
rem -- Exploits variable expansion and the pushd stack to set the current
|
||||
rem -- directory without leaking a pushd.
|
||||
popd
|
||||
setlocal
|
||||
set NewPath=%CD%
|
||||
endlocal & popd & cd /d "%NewPath%"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user