Use baseToString in _.truncate.

This commit is contained in:
John-David Dalton
2016-04-17 07:17:36 -07:00
parent 353113f17f
commit 27dfe542bd
2 changed files with 9 additions and 2 deletions

View File

@@ -14249,7 +14249,7 @@
if (isObject(options)) { if (isObject(options)) {
var separator = 'separator' in options ? options.separator : separator; var separator = 'separator' in options ? options.separator : separator;
length = 'length' in options ? toInteger(options.length) : length; length = 'length' in options ? toInteger(options.length) : length;
omission = 'omission' in options ? toString(options.omission) : omission; omission = 'omission' in options ? baseToString(options.omission) : omission;
} }
string = toString(string); string = toString(string);
@@ -14289,7 +14289,7 @@
} }
result = result.slice(0, newEnd === undefined ? end : newEnd); result = result.slice(0, newEnd === undefined ? end : newEnd);
} }
} else if (string.indexOf(separator, end) != end) { } else if (string.indexOf(baseToString(separator), end) != end) {
var index = result.lastIndexOf(separator); var index = result.lastIndexOf(separator);
if (index > -1) { if (index > -1) {
result = result.slice(0, index); result = result.slice(0, index);

View File

@@ -21856,6 +21856,13 @@
assert.strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]'); assert.strictEqual(_.truncate(string, { 'omission': ' [...]' }), 'hi-diddly-ho there, neig [...]');
}); });
QUnit.test('should coerce nullish `omission` values to strings', function(assert) {
assert.expect(2);
assert.strictEqual(_.truncate(string, { 'omission': null }), 'hi-diddly-ho there, neighbnull');
assert.strictEqual(_.truncate(string, { 'omission': undefined }), 'hi-diddly-ho there, nundefined');
});
QUnit.test('should support a `length` option', function(assert) { QUnit.test('should support a `length` option', function(assert) {
assert.expect(1); assert.expect(1);