Skip to content

Commit

Permalink
fix: sanitize ensure.case #211 (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl committed Dec 26, 2017
1 parent 52514d6 commit 3c73a21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions @commitlint/ensure/src/case.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions @commitlint/ensure/src/case.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 3c73a21

Please sign in to comment.