Escape parentheses for dropped files/folders (#1935)

* Escape parentheses for dropped files/folders

Fixes #1933

* Cleanup regex

* Wrap dropped path in single-quote

* Escape single quote inside single quote

* Handle escaping with current shell

* Cleanup escape
This commit is contained in:
Albin Ekblom 2017-06-14 18:12:03 +02:00 committed by Guillermo Rauch
parent 6d99a6df31
commit 0bf10f3768
3 changed files with 21 additions and 8 deletions

View file

@ -264,8 +264,18 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
session.resize({cols, rows}); session.resize({cols, rows});
}); });
rpc.on('data', ({uid, data}) => { rpc.on('data', ({uid, data, escaped}) => {
sessions.get(uid).write(data); 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}) => { rpc.on('open external', ({url}) => {
@ -311,8 +321,10 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
const protocol = typeof url === 'string' && parseUrl(url).protocol; const protocol = typeof url === 'string' && parseUrl(url).protocol;
if (protocol === 'file:') { if (protocol === 'file:') {
event.preventDefault(); 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:') { } else if (protocol === 'http:' || protocol === 'https:') {
event.preventDefault(); event.preventDefault();
rpc.emit('session data send', {data: url}); rpc.emit('session data send', {data: url});

View file

@ -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) { return function (dispatch, getState) {
dispatch({ dispatch({
type: SESSION_USER_DATA, type: SESSION_USER_DATA,
@ -148,7 +148,8 @@ export function sendSessionData(uid, data) {
effect() { effect() {
// If no uid is passed, data is sent to the active session. // If no uid is passed, data is sent to the active session.
const targetUid = uid || getState().sessions.activeUid; const targetUid = uid || getState().sessions.activeUid;
rpc.emit('data', {uid: targetUid, data});
rpc.emit('data', {uid: targetUid, data, escaped});
} }
}); });
}; };

View file

@ -70,8 +70,8 @@ rpc.on('session data', d => {
} }
}); });
rpc.on('session data send', ({uid, data}) => { rpc.on('session data send', ({uid, data, escaped}) => {
store_.dispatch(sessionActions.sendSessionData(uid, data)); store_.dispatch(sessionActions.sendSessionData(uid, data, escaped));
}); });
rpc.on('session exit', ({uid}) => { rpc.on('session exit', ({uid}) => {