Skip to content

Commit 6fc0529

Browse files
authored
Strip quotes from debug configurations and fix an issue with quotes in paths (#12471)
1 parent c976dba commit 6fc0529

File tree

3 files changed

+32
-24
lines changed

3 files changed

+32
-24
lines changed

Extension/src/Debugger/configurationProvider.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,16 +1162,16 @@ abstract class DefaultConfigurationProvider implements IConfigurationAssetProvid
11621162

11631163
class WindowsConfigurationProvider extends DefaultConfigurationProvider {
11641164
private executable: string = "a.exe";
1165-
private pipeProgram: string = "<" + localize("path.to.pipe.program", "full path to pipe program such as {0}", "plink.exe").replace(/"/g, '\\"') + ">";
1165+
private pipeProgram: string = "<" + localize("path.to.pipe.program", "full path to pipe program such as {0}", "plink.exe").replace(/"/g, '') + ">";
11661166
private MIMode: string = 'gdb';
11671167
private setupCommandsBlock: string = `"setupCommands": [
11681168
{
1169-
"description": "${localize("enable.pretty.printing", "Enable pretty-printing for {0}", "gdb").replace(/"/g, '\\"')}",
1169+
"description": "${localize("enable.pretty.printing", "Enable pretty-printing for {0}", "gdb").replace(/"/g, '')}",
11701170
"text": "-enable-pretty-printing",
11711171
"ignoreFailures": true
11721172
},
11731173
{
1174-
"description": "${localize("enable.intel.disassembly.flavor", "Set Disassembly Flavor to {0}", "Intel").replace(/"/g, '\\"')}",
1174+
"description": "${localize("enable.intel.disassembly.flavor", "Set Disassembly Flavor to {0}", "Intel").replace(/"/g, '')}",
11751175
"text": "-gdb-set disassembly-flavor intel",
11761176
"ignoreFailures": true
11771177
}
@@ -1205,12 +1205,12 @@ class LinuxConfigurationProvider extends DefaultConfigurationProvider {
12051205
private MIMode: string = 'gdb';
12061206
private setupCommandsBlock: string = `"setupCommands": [
12071207
{
1208-
"description": "${localize("enable.pretty.printing", "Enable pretty-printing for {0}", "gdb").replace(/"/g, '\\"')}",
1208+
"description": "${localize("enable.pretty.printing", "Enable pretty-printing for {0}", "gdb").replace(/"/g, '')}",
12091209
"text": "-enable-pretty-printing",
12101210
"ignoreFailures": true
12111211
},
12121212
{
1213-
"description": "${localize("enable.intel.disassembly.flavor", "Set Disassembly Flavor to {0}", "Intel").replace(/"/g, '\\"')}",
1213+
"description": "${localize("enable.intel.disassembly.flavor", "Set Disassembly Flavor to {0}", "Intel").replace(/"/g, '')}",
12141214
"text": "-gdb-set disassembly-flavor intel",
12151215
"ignoreFailures": true
12161216
}

Extension/src/Debugger/configurations.ts

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function createLaunchString(name: string, type: string, executable: string): str
9292
return `"name": "${name}",
9393
"type": "${type}",
9494
"request": "launch",
95-
"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '\\"')}",
95+
"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '')}",
9696
"args": [],
9797
"stopAtEntry": false,
9898
"cwd": "$\{fileDirname\}",
@@ -106,15 +106,15 @@ function createAttachString(name: string, type: string, executable: string): str
106106
"name": "${name}",
107107
"type": "${type}",
108108
"request": "attach",{0}
109-
`, [type === "cppdbg" ? `${os.EOL}"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '\\"')}",` : ""]);
109+
`, [type === "cppdbg" ? `${os.EOL}"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '')}",` : ""]);
110110
}
111111

112112
function createRemoteAttachString(name: string, type: string, executable: string): string {
113113
return `
114114
"name": "${name}",
115115
"type": "${type}",
116116
"request": "attach",
117-
"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '\\"')}",
117+
"program": "${localize("enter.program.name", "enter program name, for example {0}", "$\{workspaceFolder\}" + "/" + executable).replace(/"/g, '')}",
118118
"processId": "$\{command:pickRemoteProcess\}"
119119
`;
120120
}
@@ -158,7 +158,7 @@ abstract class Configuration implements IConfiguration {
158158
export class MIConfigurations extends Configuration {
159159

160160
public GetLaunchConfiguration(): IConfigurationSnippet {
161-
const name: string = `(${this.MIMode}) ${localize("launch.string", "Launch").replace(/"/g, '\\"')}`;
161+
const name: string = `(${this.MIMode}) ${localize("launch.string", "Launch").replace(/"/g, '')}`;
162162

163163
const body: string = formatString(`{
164164
\t${indentJsonString(createLaunchString(name, this.miDebugger, this.executable))},
@@ -168,15 +168,15 @@ export class MIConfigurations extends Configuration {
168168

169169
return {
170170
"label": configPrefix + name,
171-
"description": localize("launch.with", "Launch with {0}.", this.MIMode).replace(/"/g, '\\"'),
171+
"description": localize("launch.with", "Launch with {0}.", this.MIMode).replace(/"/g, ''),
172172
"bodyText": body.trim(),
173173
"isInitialConfiguration": true,
174174
"debuggerType": DebuggerType.cppdbg
175175
};
176176
}
177177

178178
public GetAttachConfiguration(): IConfigurationSnippet {
179-
const name: string = `(${this.MIMode}) ${localize("attach.string", "Attach").replace(/"/g, '\\"')}`;
179+
const name: string = `(${this.MIMode}) ${localize("attach.string", "Attach").replace(/"/g, '')}`;
180180

181181
const body: string = formatString(`{
182182
\t${indentJsonString(createAttachString(name, this.miDebugger, this.executable))}
@@ -186,7 +186,7 @@ export class MIConfigurations extends Configuration {
186186

187187
return {
188188
"label": configPrefix + name,
189-
"description": localize("attach.with", "Attach with {0}.", this.MIMode).replace(/"/g, '\\"'),
189+
"description": localize("attach.with", "Attach with {0}.", this.MIMode).replace(/"/g, ''),
190190
"bodyText": body.trim(),
191191
"debuggerType": DebuggerType.cppdbg
192192
};
@@ -197,7 +197,7 @@ export class MIConfigurations extends Configuration {
197197
export class PipeTransportConfigurations extends Configuration {
198198

199199
public GetLaunchConfiguration(): IConfigurationSnippet {
200-
const name: string = `(${this.MIMode}) ${localize("pipe.launch", "Pipe Launch").replace(/"/g, '\\"')}`;
200+
const name: string = `(${this.MIMode}) ${localize("pipe.launch", "Pipe Launch").replace(/"/g, '')}`;
201201

202202
const body: string = formatString(`
203203
{
@@ -208,15 +208,15 @@ export class PipeTransportConfigurations extends Configuration {
208208

209209
return {
210210
"label": configPrefix + name,
211-
"description": localize("pipe.launch.with", "Pipe Launch with {0}.", this.MIMode).replace(/"/g, '\\"'),
211+
"description": localize("pipe.launch.with", "Pipe Launch with {0}.", this.MIMode).replace(/"/g, ''),
212212
"bodyText": body.trim(),
213213
"debuggerType": DebuggerType.cppdbg
214214
};
215215

216216
}
217217

218218
public GetAttachConfiguration(): IConfigurationSnippet {
219-
const name: string = `(${this.MIMode}) ${localize("pipe.attach", "Pipe Attach").replace(/"/g, '\\"')}`;
219+
const name: string = `(${this.MIMode}) ${localize("pipe.attach", "Pipe Attach").replace(/"/g, '')}`;
220220

221221
const body: string = formatString(`
222222
{
@@ -226,7 +226,7 @@ export class PipeTransportConfigurations extends Configuration {
226226
}`, [this.additionalProperties ? `,${os.EOL}\t${indentJsonString(this.additionalProperties)}` : ""]);
227227
return {
228228
"label": configPrefix + name,
229-
"description": localize("pipe.attach.with", "Pipe Attach with {0}.", this.MIMode).replace(/"/g, '\\"'),
229+
"description": localize("pipe.attach.with", "Pipe Attach with {0}.", this.MIMode).replace(/"/g, ''),
230230
"bodyText": body.trim(),
231231
"debuggerType": DebuggerType.cppdbg
232232
};
@@ -237,7 +237,7 @@ export class PipeTransportConfigurations extends Configuration {
237237
export class WindowsConfigurations extends Configuration {
238238

239239
public GetLaunchConfiguration(): IConfigurationSnippet {
240-
const name: string = `(Windows) ${localize("launch.string", "Launch").replace(/"/g, '\\"')}`;
240+
const name: string = `(Windows) ${localize("launch.string", "Launch").replace(/"/g, '')}`;
241241

242242
const body: string = `
243243
{
@@ -246,7 +246,7 @@ export class WindowsConfigurations extends Configuration {
246246

247247
return {
248248
"label": configPrefix + name,
249-
"description": localize("launch.with.vs.debugger", "Launch with the Visual Studio C/C++ debugger.").replace(/"/g, '\\"'),
249+
"description": localize("launch.with.vs.debugger", "Launch with the Visual Studio C/C++ debugger.").replace(/"/g, ''),
250250
"bodyText": body.trim(),
251251
"isInitialConfiguration": true,
252252
"debuggerType": DebuggerType.cppvsdbg
@@ -255,7 +255,7 @@ export class WindowsConfigurations extends Configuration {
255255
}
256256

257257
public GetAttachConfiguration(): IConfigurationSnippet {
258-
const name: string = `(Windows) ${localize("attach.string", "Attach").replace(/"/g, '\\"')}`;
258+
const name: string = `(Windows) ${localize("attach.string", "Attach").replace(/"/g, '')}`;
259259

260260
const body: string = `
261261
{
@@ -264,7 +264,7 @@ export class WindowsConfigurations extends Configuration {
264264

265265
return {
266266
"label": configPrefix + name,
267-
"description": localize("attach.with.vs.debugger", "Attach to a process with the Visual Studio C/C++ debugger.").replace(/"/g, '\\"'),
267+
"description": localize("attach.with.vs.debugger", "Attach to a process with the Visual Studio C/C++ debugger.").replace(/"/g, ''),
268268
"bodyText": body.trim(),
269269
"debuggerType": DebuggerType.cppvsdbg
270270
};
@@ -277,7 +277,7 @@ export class WSLConfigurations extends Configuration {
277277
public bashPipeProgram = process.arch === 'ia32' ? "${env:windir}\\\\sysnative\\\\bash.exe" : "${env:windir}\\\\system32\\\\bash.exe";
278278

279279
public GetLaunchConfiguration(): IConfigurationSnippet {
280-
const name: string = `(${this.MIMode}) ${localize("bash.on.windows.launch", "Bash on Windows Launch").replace(/"/g, '\\"')}`;
280+
const name: string = `(${this.MIMode}) ${localize("bash.on.windows.launch", "Bash on Windows Launch").replace(/"/g, '')}`;
281281

282282
const body: string = formatString(`
283283
{
@@ -287,14 +287,14 @@ export class WSLConfigurations extends Configuration {
287287

288288
return {
289289
"label": configPrefix + name,
290-
"description": localize("launch.bash.windows", "Launch in Bash on Windows using {0}.", this.MIMode).replace(/"/g, '\\"'),
290+
"description": localize("launch.bash.windows", "Launch in Bash on Windows using {0}.", this.MIMode).replace(/"/g, ''),
291291
"bodyText": body.trim(),
292292
"debuggerType": DebuggerType.cppdbg
293293
};
294294
}
295295

296296
public GetAttachConfiguration(): IConfigurationSnippet {
297-
const name: string = `(${this.MIMode}) ${localize("bash.on.windows.attach", "Bash on Windows Attach").replace(/"/g, '\\"')}`;
297+
const name: string = `(${this.MIMode}) ${localize("bash.on.windows.attach", "Bash on Windows Attach").replace(/"/g, '')}`;
298298

299299
const body: string = formatString(`
300300
{
@@ -304,7 +304,7 @@ export class WSLConfigurations extends Configuration {
304304

305305
return {
306306
"label": configPrefix + name,
307-
"description": localize("remote.attach.bash.windows", "Attach to a remote process running in Bash on Windows using {0}.", this.MIMode).replace(/"/g, '\\"'),
307+
"description": localize("remote.attach.bash.windows", "Attach to a remote process running in Bash on Windows using {0}.", this.MIMode).replace(/"/g, ''),
308308
"bodyText": body.trim(),
309309
"debuggerType": DebuggerType.cppdbg
310310
};

Extension/src/LanguageServer/configurations.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,11 +1539,19 @@ export class CppProperties {
15391539
}
15401540

15411541
if (assumeRelative) {
1542+
let quoted = false;
1543+
if (result.startsWith('"') && result.endsWith('"')) {
1544+
quoted = true;
1545+
result = result.slice(1, -1);
1546+
}
15421547
// Make sure all paths result to an absolute path.
15431548
// Do not add the root path to an unresolved env variable.
15441549
if (!result.includes("env:") && !path.isAbsolute(result) && this.rootUri) {
15451550
result = path.join(this.rootUri.fsPath, result);
15461551
}
1552+
if (quoted) {
1553+
result = `"${result}"`;
1554+
}
15471555
}
15481556

15491557
return result;

0 commit comments

Comments
 (0)