Skip to content

Commit af67b5b

Browse files
committed
Find first and last character of [ & ] before substring
1 parent fdf45c9 commit af67b5b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/assets.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,16 @@ function addLaunchJsonIfNecessary(generator: AssetGenerator, operations: Operati
457457
let launchJson: string = generator.createLaunchJson(isWebProject);
458458

459459
if (existingLaunchConfigs) {
460-
launchJson = launchJson.substring(0, launchJson.length-1);
461460
let existingLaunchConfigsString = JSON.stringify(existingLaunchConfigs, null, ' ');
462-
existingLaunchConfigsString = existingLaunchConfigsString.substring(1, existingLaunchConfigsString.length-1);
463-
launchJson = `${launchJson},${existingLaunchConfigsString}]`;
461+
const lastBracket = launchJson.lastIndexOf(']');
462+
const lastBracketInExistingConfig = existingLaunchConfigsString.lastIndexOf(']');
463+
const firstBracketInExistingConfig = existingLaunchConfigsString.lastIndexOf('[');
464+
465+
if (lastBracket !== -1 && lastBracketInExistingConfig !== -1 && firstBracketInExistingConfig !== -1) {
466+
launchJson = launchJson.substring(0, lastBracket);
467+
existingLaunchConfigsString = existingLaunchConfigsString.substring(firstBracketInExistingConfig, lastBracketInExistingConfig);
468+
launchJson = `${launchJson},${existingLaunchConfigsString}]`;
469+
}
464470
}
465471

466472
const configurationsMassaged: string = indentJsonString(launchJson);

0 commit comments

Comments
 (0)