diff --git a/src/functions/__tests__/casing.test.ts b/src/functions/__tests__/casing.test.ts index d5fc5596e..8da9fa887 100644 --- a/src/functions/__tests__/casing.test.ts +++ b/src/functions/__tests__/casing.test.ts @@ -265,6 +265,13 @@ describe('casing', () => { ); }); + test.each(Object.values(CasingType))('properly detects leading char for %s casing', casing => { + expect(runCasing('/', casing, true, { allowLeading: true, char: '/' })).toBeUndefined(); + expect(runCasing('//', casing, true, { allowLeading: true, char: '/' })).toEqual([ + { message: `must be ${casing} case` }, + ]); + }); + test('allows advanced scenarios', () => { expect(runCasing('X-MyAmazing-Header', CasingType.pascal, true, { char: '-' })).toBeUndefined(); expect( diff --git a/src/functions/casing.ts b/src/functions/casing.ts index fffe480ae..fb85400ed 100644 --- a/src/functions/casing.ts +++ b/src/functions/casing.ts @@ -36,6 +36,15 @@ export const casing: IFunction = (targetVal, opts) => { return; } + if ( + targetVal.length === 1 && + opts.separator !== void 0 && + opts.separator.allowLeading === true && + targetVal === opts.separator.char + ) { + return; + } + const casingValidator = buildFrom(CASES[opts.type], opts); if (casingValidator.test(targetVal)) {