mirror of
https://github.com/cexll/myclaude.git
synced 2026-02-04 02:20:42 +08:00
fix: replace setx with reg add to avoid 1024-char PATH truncation (#101)
- Use reg add instead of setx to bypass Windows 1024-character limit - Add safety check for quotes/exclamation marks in PATH to prevent injection - Preserve stderr output for better error diagnostics - Update documentation with warnings about cmd PATH duplication - Add test script for PATH update validation Generated with SWE-Agent.ai Co-Authored-By: SWE-Agent.ai <noreply@swe-agent.ai>
This commit is contained in:
@@ -346,8 +346,10 @@ $Env:PATH = "$HOME\bin;$Env:PATH"
|
||||
```
|
||||
|
||||
```batch
|
||||
REM cmd.exe - persistent for current user
|
||||
setx PATH "%USERPROFILE%\bin;%PATH%"
|
||||
REM cmd.exe - persistent for current user (use PowerShell method above instead)
|
||||
REM WARNING: This expands %PATH% which includes system PATH, causing duplication
|
||||
REM Note: Using reg add instead of setx to avoid 1024-character truncation limit
|
||||
reg add "HKCU\Environment" /v Path /t REG_EXPAND_SZ /d "%USERPROFILE%\bin;%PATH%" /f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -282,8 +282,10 @@ $Env:PATH = "$HOME\bin;$Env:PATH"
|
||||
```
|
||||
|
||||
```batch
|
||||
REM cmd.exe - 永久添加(当前用户)
|
||||
setx PATH "%USERPROFILE%\bin;%PATH%"
|
||||
REM cmd.exe - 永久添加(当前用户)(建议使用上面的 PowerShell 方法)
|
||||
REM 警告:此命令会展开 %PATH% 包含系统 PATH,导致重复
|
||||
REM 注意:使用 reg add 而非 setx 以避免 1024 字符截断限制
|
||||
reg add "HKCU\Environment" /v Path /t REG_EXPAND_SZ /d "%USERPROFILE%\bin;%PATH%" /f
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
15
install.bat
15
install.bat
@@ -117,11 +117,18 @@ if "!ALREADY_IN_USERPATH!"=="1" (
|
||||
set "USER_PATH_NEW=!PCT!USERPROFILE!PCT!\bin"
|
||||
)
|
||||
rem Persist update to HKCU\Environment\Path (user scope)
|
||||
setx Path "!USER_PATH_NEW!" >nul
|
||||
if errorlevel 1 (
|
||||
echo WARNING: Failed to append %%USERPROFILE%%\bin to your user PATH.
|
||||
rem Use reg add instead of setx to avoid 1024-character limit
|
||||
echo(!USER_PATH_NEW! | findstr /C:"\"" /C:"!" >nul
|
||||
if not errorlevel 1 (
|
||||
echo WARNING: Your PATH contains quotes or exclamation marks that may cause issues.
|
||||
echo Skipping automatic PATH update. Please add %%USERPROFILE%%\bin to your PATH manually.
|
||||
) else (
|
||||
echo Added %%USERPROFILE%%\bin to your user PATH.
|
||||
reg add "HKCU\Environment" /v Path /t REG_EXPAND_SZ /d "!USER_PATH_NEW!" /f >nul
|
||||
if errorlevel 1 (
|
||||
echo WARNING: Failed to append %%USERPROFILE%%\bin to your user PATH.
|
||||
) else (
|
||||
echo Added %%USERPROFILE%%\bin to your user PATH.
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
67
test_install_path.bat
Normal file
67
test_install_path.bat
Normal file
@@ -0,0 +1,67 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
echo Testing PATH update with long strings...
|
||||
echo.
|
||||
|
||||
rem Create a very long PATH string (over 1024 characters)
|
||||
set "LONG_PATH="
|
||||
for /L %%i in (1,1,30) do (
|
||||
set "LONG_PATH=!LONG_PATH!C:\VeryLongDirectoryName%%i\SubDirectory\AnotherSubDirectory;"
|
||||
)
|
||||
|
||||
echo Generated PATH length:
|
||||
echo !LONG_PATH! > temp_path.txt
|
||||
for %%A in (temp_path.txt) do set "PATH_LENGTH=%%~zA"
|
||||
del temp_path.txt
|
||||
echo !PATH_LENGTH! bytes
|
||||
|
||||
rem Test 1: Verify reg add can handle long strings
|
||||
echo.
|
||||
echo Test 1: Testing reg add with long PATH...
|
||||
set "TEST_PATH=!LONG_PATH!%%USERPROFILE%%\bin"
|
||||
reg add "HKCU\Environment" /v TestPath /t REG_EXPAND_SZ /d "!TEST_PATH!" /f >nul 2>nul
|
||||
if errorlevel 1 (
|
||||
echo FAIL: reg add failed with long PATH
|
||||
goto :cleanup
|
||||
) else (
|
||||
echo PASS: reg add succeeded with long PATH
|
||||
)
|
||||
|
||||
rem Test 2: Verify the value was stored correctly
|
||||
echo.
|
||||
echo Test 2: Verifying stored value length...
|
||||
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v TestPath 2^>nul ^| findstr /I "TestPath"') do set "STORED_PATH=%%B"
|
||||
echo !STORED_PATH! > temp_stored.txt
|
||||
for %%A in (temp_stored.txt) do set "STORED_LENGTH=%%~zA"
|
||||
del temp_stored.txt
|
||||
echo Stored PATH length: !STORED_LENGTH! bytes
|
||||
|
||||
if !STORED_LENGTH! LSS 1024 (
|
||||
echo FAIL: Stored PATH was truncated
|
||||
goto :cleanup
|
||||
) else (
|
||||
echo PASS: Stored PATH was not truncated
|
||||
)
|
||||
|
||||
rem Test 3: Verify %%USERPROFILE%%\bin is present
|
||||
echo.
|
||||
echo Test 3: Verifying %%USERPROFILE%%\bin is in stored PATH...
|
||||
echo !STORED_PATH! | findstr /I "USERPROFILE" >nul
|
||||
if errorlevel 1 (
|
||||
echo FAIL: %%USERPROFILE%%\bin not found in stored PATH
|
||||
goto :cleanup
|
||||
) else (
|
||||
echo PASS: %%USERPROFILE%%\bin found in stored PATH
|
||||
)
|
||||
|
||||
echo.
|
||||
echo ========================================
|
||||
echo All tests PASSED
|
||||
echo ========================================
|
||||
|
||||
:cleanup
|
||||
echo.
|
||||
echo Cleaning up test registry key...
|
||||
reg delete "HKCU\Environment" /v TestPath /f >nul 2>nul
|
||||
endlocal
|
||||
Reference in New Issue
Block a user