Skip to content

Commit 42e8877

Browse files
quote strings (hestiacp#4537)
* quote strings Previously if a password contained whitespace like `pass word` or shell-metacharacters like `pass&word` or `pass'word` , it would generate an invalid install command. The code is basically just https://github.com/hestiacp/phpquoteshellarg ported to javascript. --------- Co-authored-by: Jaap Marcus <9754650+jaapmarcus@users.noreply.github.com>
1 parent 1e13c17 commit 42e8877

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

docs/.vitepress/theme/components/InstallBuilder.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ describe('InstallBuilder', () => {
6666
const textInput = screen.getByLabelText(options[1].description);
6767
await fireEvent.update(textInput, 'custom-value');
6868

69-
expect(screen.getByDisplayValue(/bash hst-install.sh --option2 custom-value/)).toBeTruthy();
69+
expect(screen.getByDisplayValue(/bash hst-install.sh --option2 'custom-value'/)).toBeTruthy();
7070
});
7171

7272
it('updates the installation command when option select input changes', async () => {

docs/.vitepress/theme/components/InstallBuilder.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ const toggleOption = (option) => {
107107
const installCommand = ref("bash hst-install.sh");
108108
watchEffect(() => {
109109
let cmd = "bash hst-install.sh";
110+
let quoteshellarg = function (str) {
111+
if (!str) return "''";
112+
return "'" + str.replace(/'/g, "'\\''") + "'";
113+
};
110114
for (const [key, { enabled, value }] of Object.entries(selectedOptions.value)) {
111115
const opt = options.find((o) => o.flag === key);
112116
if (opt.flag == "force" && enabled) {
@@ -116,7 +120,8 @@ watchEffect(() => {
116120
cmd += ` --${key} ${enabled ? "yes" : "no"}`;
117121
}
118122
} else if (enabled && value !== opt.default) {
119-
cmd += ` --${key} ${value}`;
123+
let value_quoted = quoteshellarg(value);
124+
cmd += ` --${key} ${value_quoted}`;
120125
}
121126
}
122127
installCommand.value = cmd;

0 commit comments

Comments
 (0)