diff --git a/app/index.js b/app/index.js index 563578f7..15d80bd5 100644 --- a/app/index.js +++ b/app/index.js @@ -264,8 +264,18 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { session.resize({cols, rows}); }); - rpc.on('data', ({uid, data}) => { - sessions.get(uid).write(data); + rpc.on('data', ({uid, data, escaped}) => { + const session = sessions.get(uid); + + if (escaped) { + const escapedData = session.shell.endsWith('cmd.exe') ? + `"${data}"` : // This is how cmd.exe does it + `'${data.replace(/'/g, `'\\''`)}'`; // Inside a single-quoted string nothing is interpreted + + session.write(escapedData); + } else { + session.write(data); + } }); rpc.on('open external', ({url}) => { @@ -311,8 +321,10 @@ app.on('ready', () => installDevExtensions(isDev).then(() => { const protocol = typeof url === 'string' && parseUrl(url).protocol; if (protocol === 'file:') { event.preventDefault(); - const path = fileUriToPath(url).replace(/ /g, '\\ '); - rpc.emit('session data send', {data: path}); + + const path = fileUriToPath(url); + + rpc.emit('session data send', {data: path, escaped: true}); } else if (protocol === 'http:' || protocol === 'https:') { event.preventDefault(); rpc.emit('session data send', {data: url}); diff --git a/lib/actions/sessions.js b/lib/actions/sessions.js index 07265584..2a26e4b1 100644 --- a/lib/actions/sessions.js +++ b/lib/actions/sessions.js @@ -140,7 +140,7 @@ export function resizeSession(uid, cols, rows) { }; } -export function sendSessionData(uid, data) { +export function sendSessionData(uid, data, escaped) { return function (dispatch, getState) { dispatch({ type: SESSION_USER_DATA, @@ -148,7 +148,8 @@ export function sendSessionData(uid, data) { effect() { // If no uid is passed, data is sent to the active session. const targetUid = uid || getState().sessions.activeUid; - rpc.emit('data', {uid: targetUid, data}); + + rpc.emit('data', {uid: targetUid, data, escaped}); } }); }; diff --git a/lib/index.js b/lib/index.js index 093ace47..d093ed45 100644 --- a/lib/index.js +++ b/lib/index.js @@ -70,8 +70,8 @@ rpc.on('session data', d => { } }); -rpc.on('session data send', ({uid, data}) => { - store_.dispatch(sessionActions.sendSessionData(uid, data)); +rpc.on('session data send', ({uid, data, escaped}) => { + store_.dispatch(sessionActions.sendSessionData(uid, data, escaped)); }); rpc.on('session exit', ({uid}) => {