Skip to content

Commit

Permalink
Fix/non strings (#867)
Browse files Browse the repository at this point in the history
Resolves an issue whereby non-strings can be passed into the config switch detector.

Closes #866
  • Loading branch information
steveukx authored Nov 30, 2022
1 parent e1d66b6 commit de570ac
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/unlucky-dragons-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'simple-git': patch
---

Resolves an issue whereby non-strings can be passed into the config switch detector.
4 changes: 2 additions & 2 deletions simple-git/src/lib/plugins/block-unsafe-operations-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions simple-git/test/integration/plugin.unsafe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit de570ac

Please sign in to comment.