From 03aeefc2baa5d161fb6dc630c74a1713633ac84b Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Tue, 26 Dec 2017 19:49:29 +0100 Subject: [PATCH] fix: sanitize ensure.case #211 (#217) --- @commitlint/ensure/src/case.js | 8 +++++--- @commitlint/ensure/src/case.test.js | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/@commitlint/ensure/src/case.js b/@commitlint/ensure/src/case.js index 10a309cf68..7aea04fa2f 100644 --- a/@commitlint/ensure/src/case.js +++ b/@commitlint/ensure/src/case.js @@ -24,11 +24,13 @@ function ensureCase(raw = '', target = 'lowercase') { case 'uppercase': return input.toUpperCase() === input; case 'sentence-case': - case 'sentencecase': + case 'sentencecase': { + const word = input.split(' ')[0]; return ( - ensureCase(raw.charAt(0), 'upper-case') && - ensureCase(raw.substring(1), 'lower-case') + ensureCase(word.charAt(0), 'upper-case') && + ensureCase(word.slice(1), 'lower-case') ); + } case 'lower-case': case 'lowercase': case 'lowerCase': // Backwards compat config-angular v4 diff --git a/@commitlint/ensure/src/case.test.js b/@commitlint/ensure/src/case.test.js index cefae32942..db84be70ad 100644 --- a/@commitlint/ensure/src/case.test.js +++ b/@commitlint/ensure/src/case.test.js @@ -54,8 +54,8 @@ test('false for UPPERCASE on sentencecase', t => { t.is(ensure('UPPERCASE', 'sentence-case'), false); }); -test('false for Start Case on sentencecase', t => { - t.is(ensure('Start Case', 'sentence-case'), false); +test('true for Start Case on sentencecase', t => { + t.is(ensure('Start Case', 'sentence-case'), true); }); test('false for PascalCase on sentencecase', t => {