Skip to content

Commit 5092323

Browse files
committed
fail on invalid patterns
1 parent c9152a1 commit 5092323

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

packages/core/src/awsService/ec2/model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,9 @@ export class Ec2Connecter implements vscode.Disposable {
351351
* @returns bash command to remove lines from file.
352352
*/
353353
export function getRemoveLinesCommand(pattern: string, hostOS: Ec2OS, filepath: string): string {
354+
if (pattern.includes('/')) {
355+
throw new ToolkitError(`ec2: cannot match pattern containing '/', given: ${pattern}`)
356+
}
354357
// Linux allows not passing extension to -i, whereas macOS requires zero length extension.
355358
return `sed -i${isLinux(hostOS) ? '' : " ''"} /${pattern}/d ${filepath}`
356359
}

packages/core/src/test/awsService/ec2/model.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,8 @@ describe('getRemoveLinesCommand', async function () {
288288
assert.ok(!alCommand.includes("''"))
289289
assert.strictEqual(ubuntuCommand, alCommand)
290290
})
291+
292+
it('throws when given invalid pattern', function () {
293+
assert.throws(() => getRemoveLinesCommand('pat/tern', 'macOS', 'test.txt'))
294+
})
291295
})

0 commit comments

Comments
 (0)