From de570acd052660bad0165347de5d2f86a494ae1b Mon Sep 17 00:00:00 2001 From: Steve King Date: Wed, 30 Nov 2022 15:15:57 +0000 Subject: [PATCH] Fix/non strings (#867) Resolves an issue whereby non-strings can be passed into the config switch detector. Closes #866 --- .changeset/unlucky-dragons-fry.md | 5 +++++ .../src/lib/plugins/block-unsafe-operations-plugin.ts | 4 ++-- simple-git/test/integration/plugin.unsafe.spec.ts | 6 ++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 .changeset/unlucky-dragons-fry.md diff --git a/.changeset/unlucky-dragons-fry.md b/.changeset/unlucky-dragons-fry.md new file mode 100644 index 00000000..50742f4b --- /dev/null +++ b/.changeset/unlucky-dragons-fry.md @@ -0,0 +1,5 @@ +--- +'simple-git': patch +--- + +Resolves an issue whereby non-strings can be passed into the config switch detector. diff --git a/simple-git/src/lib/plugins/block-unsafe-operations-plugin.ts b/simple-git/src/lib/plugins/block-unsafe-operations-plugin.ts index 86aded66..774b2a50 100644 --- a/simple-git/src/lib/plugins/block-unsafe-operations-plugin.ts +++ b/simple-git/src/lib/plugins/block-unsafe-operations-plugin.ts @@ -3,8 +3,8 @@ import type { SimpleGitPlugin } from './simple-git-plugin'; import { GitPluginError } from '../errors/git-plugin-error'; import type { SimpleGitPluginConfig } from '../types'; -function isConfigSwitch(arg: string) { - return arg.trim().toLowerCase() === '-c'; +function isConfigSwitch(arg: string | unknown) { + return typeof arg === 'string' && arg.trim().toLowerCase() === '-c'; } function preventProtocolOverride(arg: string, next: string) { diff --git a/simple-git/test/integration/plugin.unsafe.spec.ts b/simple-git/test/integration/plugin.unsafe.spec.ts index e4b72f7d..48b6023b 100644 --- a/simple-git/test/integration/plugin.unsafe.spec.ts +++ b/simple-git/test/integration/plugin.unsafe.spec.ts @@ -13,6 +13,12 @@ describe('add', () => { beforeEach(async () => (context = await createTestContext())); + it('ignores non string arguments', async () => { + const { threw } = await promiseResult(newSimpleGit(context.root).raw([['init']] as any)); + + expect(threw).toBe(false); + }); + it('allows overriding protocol when opting in to unsafe practices', async () => { const { threw } = await promiseResult( newSimpleGit(context.root, { unsafe: { allowUnsafeProtocolOverride: true } }).raw(