From dcec88226294d95bec583cc77a9e6b71b439e087 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 28 Mar 2016 07:57:37 -0700 Subject: [PATCH] Ensure `_.words` detects compound words where an all caps word is next to a capitalized word. [closes #2163] --- lodash.js | 2 +- test/test.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lodash.js b/lodash.js index a35622d2a..170b47c78 100644 --- a/lodash.js +++ b/lodash.js @@ -229,7 +229,7 @@ ].join('|'), 'g'); /** Used to detect strings that need a more robust regexp to match words. */ - var reHasComplexWord = /[a-z][A-Z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; + var reHasComplexWord = /[a-z][A-Z]|[A-Z]{2,}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; /** Used to assign default `context` object properties. */ var contextProps = [ diff --git a/test/test.js b/test/test.js index c6d925434..30ee33be6 100644 --- a/test/test.js +++ b/test/test.js @@ -24020,17 +24020,20 @@ }); QUnit.test('should work with compound words', function(assert) { - assert.expect(9); + assert.expect(12); assert.deepEqual(_.words('12Feet'), ['12', 'Feet']); + assert.deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']); assert.deepEqual(_.words('enable 6h format'), ['enable', '6', 'h', 'format']); assert.deepEqual(_.words('enable 24H format'), ['enable', '24', 'H', 'format']); assert.deepEqual(_.words('isISO8601'), ['is', 'ISO', '8601']); + assert.deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']); assert.deepEqual(_.words('tooLegit2Quit'), ['too', 'Legit', '2', 'Quit']); assert.deepEqual(_.words('walk500Miles'), ['walk', '500', 'Miles']); assert.deepEqual(_.words('xhr2Request'), ['xhr', '2', 'Request']); - assert.deepEqual(_.words('aeiouAreVowels'), ['aeiou', 'Are', 'Vowels']); - assert.deepEqual(_.words('LETTERSAeiouAreVowels'), ['LETTERS', 'Aeiou', 'Are', 'Vowels']); + assert.deepEqual(_.words('XMLHttp'), ['XML', 'Http']); + assert.deepEqual(_.words('XmlHTTP'), ['Xml', 'HTTP']); + assert.deepEqual(_.words('XmlHttp'), ['Xml', 'Http']); }); QUnit.test('should work with compound words containing diacritical marks', function(assert) {