Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape characters in project name #839

Merged
merged 5 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
.DS_Store
test/workspace/.vscode
dist
jdt-language-server-latest.tar.gz
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
},
"stripe.projectName": {
"type": "string",
"description": "the project name to read from for config (default \"default\")"
"description": "the project name to read from for config (default \"default\")",
"pattern": "^[a-zA-Z0-9_-\\s]+$"
},
"stripe.telemetry.enabled": {
"type": "boolean",
Expand Down
26 changes: 16 additions & 10 deletions src/stripeTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,29 @@ export class StripeTerminal {
'stripe',
new vscode.ShellExecution(cliPath, [
command,
...args.map((arg) => ({
quoting: vscode.ShellQuoting.Strong,
value: arg,
})),
...globalCLIFlags.map((arg) => ({
quoting: vscode.ShellQuoting.Strong,
value: arg,
})),
])
...args,
...globalCLIFlags
],
{
shellQuoting: {
escape: {
escapeChar: '\\',
charsToEscape: '&`|"\'',
}
}
}
)
));
}

// The Stripe CLI supports a number of flags for every command. See https://stripe.com/docs/cli/flags
private getGlobalCLIFlags(): Array<string> {
const stripeConfig = vscode.workspace.getConfiguration('stripe');

const projectName = stripeConfig.get('projectName', null);
let projectName = stripeConfig.get<string | null>('projectName', null);
if (projectName !== null) {
projectName = projectName.replace(/[\\"'`]/g, '');
}

const projectNameFlag = projectName ? ['--project-name', projectName] : [];

Expand Down
18 changes: 10 additions & 8 deletions test/suite/stripeTerminal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ suite('stripeTerminal', function () {
'stripe',
new vscode.ShellExecution(path, [
'listen',
{
quoting: vscode.ShellQuoting.Strong,
value: '--forward-to'
'--forward-to',
'localhost',
],
{
shellQuoting: {
escape: {
escapeChar: '\\',
charsToEscape: '&`|"\'',
},
},
{
quoting: vscode.ShellQuoting.Strong,
value: 'localhost'
}
])
}),
),
]);
});
Expand Down
Loading