Skip to content

Commit 6d05225

Browse files
authored
Merge pull request #635 from JunoLab/sp/remoteaaaaaaaah
fix remote exec escaping
2 parents 61e94a1 + 3404cb3 commit 6d05225

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

lib/connection/process/remote.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,30 +168,41 @@ export function get_ (path, args) {
168168
}
169169
})
170170
let jlpath = atom.config.get('julia-client.remoteOptions.remoteJulia')
171+
172+
// construct something like
173+
//
174+
// /bin/sh -c 'tmux new -s sessionname '\'' julia -i -e '\'\\\'\''startup_repl'\'\\\'\'' '\''port'\'' '\'' '
175+
//
176+
// with properly escaped single quotes.
177+
171178
let exec = ''
172179
if (atom.config.get('julia-client.remoteOptions.tmux')) {
173180
let sessionName = atom.config.get('julia-client.remoteOptions.tmuxName')
174-
exec += '/bin/sh -c \''
175-
exec += `tmux new -s ${sessionName} \\"`
181+
exec += `/bin/sh -c '`
182+
exec += `tmux new -s ${sessionName} '\\''`
176183
if (threadCount() !== undefined) {
177-
exec += ` JULIA_NUM_THREADS='${threadCount()}' `
184+
exec += ` JULIA_NUM_THREADS="${threadCount()}" `
178185
}
179186
exec += jlpath
180-
exec += ' ' + args.join(' ') + ' -e \'\\\'\''
187+
exec += ` ${args.join(' ')} -e '\\'\\\\\\'\\''`
188+
// could automatically escape single quotes with `replace(/'/, `'\\'\\\\\\'\\\\\\\\\\\\\\'\\\\\\'\\''`)`,
189+
// but that's so ugly I'd rather not do that
181190
exec += fs.readFileSync(paths.script('boot_repl.jl')).toString()
182-
exec += '\'\\\'\' ' + port + ' \\" '
183-
exec += `|| tmux send-keys -t ${sessionName}.left ^A ^K ^H \'\\\'\'Juno.connect(${port})\'\\\'\' ENTER `
191+
exec += `'\\'\\\\\\'\\'' ${port} '\\'' `
192+
exec += `|| tmux send-keys -t ${sessionName}.left ^A ^K ^H '\\''Juno.connect(${port})'\\'' ENTER `
184193
exec += `&& tmux attach -t ${sessionName} `
185-
exec += '\''
194+
exec += `'`
186195
} else {
187-
exec += '/bin/sh -c \''
196+
exec += `/bin/sh -c '`
188197
if (threadCount() !== undefined) {
189-
exec += `JULIA_NUM_THREADS='${threadCount()}' `
198+
exec += `JULIA_NUM_THREADS="${threadCount()}" `
190199
}
191-
exec += jlpath + ' ' + args.join(' ') + ' -e \'\\\'\''
200+
exec += `${jlpath} ${args.join(' ')} -e '\\''`
201+
// could automatically escape single quotes with `replace(/'/, `'\\'\\\\\\'\\''`)`,
202+
// but that's so ugly I'd rather not do that
192203
exec += fs.readFileSync(paths.script('boot_repl.jl')).toString()
193-
exec += '\'\\\'\' ' + port
194-
exec += '\''
204+
exec += `'\\'' ${port}`
205+
exec += `'`
195206
}
196207

197208
conn.exec(exec, { pty: { term: "xterm-256color" } }, (err, stream) => {

script/boot_repl.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
let
2+
# NOTE: Single quotes in this file break remote execution. So dont use them.
23
if VERSION > v"0.7-"
34
port = parse(Int, popfirst!(ARGS))
45
else

0 commit comments

Comments
 (0)