Skip to content
Snippets Groups Projects
Commit e8c7b85d authored by Maxime Jacquemin's avatar Maxime Jacquemin
Browse files

Merge branch 'feature/ivette/fix-console-quotes' into 'master'

[ivette/controller] quote/unquote cmd & cwd

See merge request frama-c/frama-c!3655
parents 8d8b6aaa a22012b2
No related branches found
No related tags found
No related merge requests found
...@@ -45,14 +45,19 @@ import * as Server from 'frama-c/server'; ...@@ -45,14 +45,19 @@ import * as Server from 'frama-c/server';
// --- Configure Server // --- Configure Server
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
const quoteRe = new RegExp('^[-./:a-zA-Z0-9]+$'); const quoteRe = new RegExp('^[-_./:a-zA-Z0-9]+$');
const quote = (s: string) => (quoteRe.test(s) ? s : `"${s}"`); const quote = (s: string): string =>
(quoteRe.test(s) ? s : `"${s}"`);
const unquoteRe = new RegExp('^".*"$');
const unquote = (s: string): string =>
(unquoteRe.test(s) ? s.substring(1, s.length - 1) : s);
function dumpServerConfig(sc: Server.Configuration): string { function dumpServerConfig(sc: Server.Configuration): string {
let buffer = ''; let buffer = '';
const { cwd, command, sockaddr, params } = sc; const { cwd, command, sockaddr, params } = sc;
if (cwd) buffer += `--cwd ${quote(cwd)}\n`; if (cwd) buffer += `--cwd ${quote(cwd)}\n`;
if (command) buffer += `--command ${command}\n`; if (command) buffer += `--command ${quote(command)}\n`;
if (sockaddr) buffer += `--socket ${sockaddr}\n`; if (sockaddr) buffer += `--socket ${sockaddr}\n`;
if (params) { if (params) {
params.forEach((v: string, i: number) => { params.forEach((v: string, i: number) => {
...@@ -73,17 +78,17 @@ function buildServerConfig(argv: string[], cwd?: string) { ...@@ -73,17 +78,17 @@ function buildServerConfig(argv: string[], cwd?: string) {
const params = []; const params = [];
let command; let command;
let sockaddr; let sockaddr;
let cwdir = cwd; let cwdir = cwd ? unquote(cwd) : undefined;
for (let k = 0; k < (argv ? argv.length : 0); k++) { for (let k = 0; k < (argv ? argv.length : 0); k++) {
const v = argv[k]; const v = argv[k];
switch (v) { switch (v) {
case '--cwd': case '--cwd':
k += 1; k += 1;
cwdir = argv[k]; cwdir = unquote(argv[k]);
break; break;
case '--command': case '--command':
k += 1; k += 1;
command = argv[k]; command = unquote(argv[k]);
break; break;
case '--socket': case '--socket':
k += 1; k += 1;
...@@ -220,8 +225,10 @@ const RenderConsole = () => { ...@@ -220,8 +225,10 @@ const RenderConsole = () => {
const doReload = () => { const doReload = () => {
const cfg = Server.getConfig(); const cfg = Server.getConfig();
const hst = insertConfig(history, cfg); const hst = insertConfig(history, cfg);
const cmd = hst[0];
scratch.current = hst.slice(); scratch.current = hst.slice();
editor.setValue(hst[0]); editor.setValue(cmd);
setEmpty(cmd === '');
setHistory(hst); setHistory(hst);
setCursor(0); setCursor(0);
}; };
...@@ -251,7 +258,9 @@ const RenderConsole = () => { ...@@ -251,7 +258,9 @@ const RenderConsole = () => {
const cmd = editor.getValue(); const cmd = editor.getValue();
const pad = scratch.current; const pad = scratch.current;
pad[cursor] = cmd; pad[cursor] = cmd;
editor.setValue(pad[target]); const cmd2 = pad[target];
editor.setValue(cmd2);
setEmpty(cmd2 === '');
setCursor(target); setCursor(target);
}; };
return undefined; return undefined;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment