From 2c830252dbbb5a72154a5ac8b27c2e821bb6b4ae Mon Sep 17 00:00:00 2001 From: shoemoney Date: Sat, 28 Nov 2026 00:01:10 -0600 Subject: [PATCH] fix: preserve literal installer bin directory paths --- install.sh | 5 ++++- scripts/test-install.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/install.sh b/install.sh index 51c964f..bff940e 100755 --- a/install.sh +++ b/install.sh @@ -100,7 +100,10 @@ if [ -z "$BIN_DIR" ]; then BIN_DIR=$def fi fi -BIN_DIR=$(eval echo "$BIN_DIR") # expand a leading ~ +# Expand only a leading ~/; keep the rest of the path literal. +case "$BIN_DIR" in + '~/'*) BIN_DIR="$HOME/${BIN_DIR#\~/}" ;; +esac SUDO="" if ! mkdir -p "$BIN_DIR" 2>/dev/null || ! [ -w "$BIN_DIR" ]; then diff --git a/scripts/test-install.py b/scripts/test-install.py index 999f44d..3e26396 100644 --- a/scripts/test-install.py +++ b/scripts/test-install.py @@ -10,6 +10,42 @@ INSTALLER = Path(__file__).resolve().parents[1] / 'install.sh' class InstallTest(unittest.TestCase): + def test_bin_dir_is_literal(self): + for mode in ('flag', 'env'): + for case in ('spaces', 'tilde', 'substitution', 'backticks', 'special'): + with self.subTest(mode=mode, case=case), tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + home = root / 'home directory' + home.mkdir() + source = root / 'devbox-fixture' + source.write_text('#!/bin/sh\necho devbox-fixture\n') + source.chmod(0o755) + marker = root / 'executed' + paths = { + 'spaces': str(root / ' two spaces '), + 'tilde': '~/two spaces/bin', + 'substitution': str(root / f'$(touch {marker})'), + 'backticks': str(root / f'`touch {marker}`'), + 'special': str(root / 'literal \'single\' "double" ; & $HOME * ? [abc] \\ ~'), + } + requested = paths[case] + dest = home / requested[2:] if requested.startswith('~/') else Path(requested) + env = dict(os.environ) + for key in ('DEVBOX_INSTALL_HUB', 'DEVBOX_INSTALL_MCPD_PLUGIN', 'DEVBOX_BIN_DIR'): + env.pop(key, None) + env.update(HOME=str(home), TMPDIR=str(root), DEVBOX_BIN=str(source)) + args = ['sh', str(INSTALLER), '--no-service'] + if mode == 'flag': + args += ['--bin-dir', requested] + else: + env['DEVBOX_BIN_DIR'] = requested + result = subprocess.run(args, cwd=root, env=env, capture_output=True, text=True, timeout=10) + self.assertFalse(marker.exists(), 'bin directory input executed a command') + self.assertEqual(result.returncode, 0, result.stderr) + self.assertTrue((dest / 'devbox').is_file(), f'missing literal destination: {dest!s}\n{result.stdout}') + self.assertEqual({p.name for p in dest.iterdir()}, {'devbox'}) + self.assertEqual(subprocess.check_output([str(dest / 'devbox')], text=True), 'devbox-fixture\n') + def test_optional_plugin(self): for mode in ('default', 'flag', 'env'): with self.subTest(mode=mode), tempfile.TemporaryDirectory() as tmp: