Skip to content

Commit c6e281b

Browse files
committedFeb 20, 2021
Bump to v4.17.21
1 parent f2e7063 commit c6e281b

14 files changed

+280
-179
lines changed
 

‎README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# lodash v4.17.20
1+
# lodash v4.17.21
22

33
The [Lodash](https://lodash.com/) library exported as [Node.js](https://nodejs.org/) modules.
44

@@ -28,7 +28,7 @@ var at = require('lodash/at');
2828
var curryN = require('lodash/fp/curryN');
2929
```
3030

31-
See the [package source](https://github.com/lodash/lodash/tree/4.17.20-npm) for more details.
31+
See the [package source](https://github.com/lodash/lodash/tree/4.17.21-npm) for more details.
3232

3333
**Note:**<br>
3434
Install [n_](https://www.npmjs.com/package/n_) for Lodash use in the Node.js < 6 REPL.

‎_baseTrim.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var trimmedEndIndex = require('./_trimmedEndIndex');
2+
3+
/** Used to match leading whitespace. */
4+
var reTrimStart = /^\s+/;
5+
6+
/**
7+
* The base implementation of `_.trim`.
8+
*
9+
* @private
10+
* @param {string} string The string to trim.
11+
* @returns {string} Returns the trimmed string.
12+
*/
13+
function baseTrim(string) {
14+
return string
15+
? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
16+
: string;
17+
}
18+
19+
module.exports = baseTrim;

‎_trimmedEndIndex.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/** Used to match a single whitespace character. */
2+
var reWhitespace = /\s/;
3+
4+
/**
5+
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
6+
* character of `string`.
7+
*
8+
* @private
9+
* @param {string} string The string to inspect.
10+
* @returns {number} Returns the index of the last non-whitespace character.
11+
*/
12+
function trimmedEndIndex(string) {
13+
var index = string.length;
14+
15+
while (index-- && reWhitespace.test(string.charAt(index))) {}
16+
return index;
17+
}
18+
19+
module.exports = trimmedEndIndex;

‎core.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
var undefined;
1414

1515
/** Used as the semantic version number. */
16-
var VERSION = '4.17.20';
16+
var VERSION = '4.17.21';
1717

1818
/** Error message constants. */
1919
var FUNC_ERROR_TEXT = 'Expected a function';

‎core.min.js

+24-25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎lodash.js

+57-9
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
var undefined;
1313

1414
/** Used as the semantic version number. */
15-
var VERSION = '4.17.20';
15+
var VERSION = '4.17.21';
1616

1717
/** Used as the size to enable large array optimizations. */
1818
var LARGE_ARRAY_SIZE = 200;
1919

2020
/** Error message constants. */
2121
var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
22-
FUNC_ERROR_TEXT = 'Expected a function';
22+
FUNC_ERROR_TEXT = 'Expected a function',
23+
INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
2324

2425
/** Used to stand-in for `undefined` hash values. */
2526
var HASH_UNDEFINED = '__lodash_hash_undefined__';
@@ -152,10 +153,11 @@
152153
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
153154
reHasRegExpChar = RegExp(reRegExpChar.source);
154155

155-
/** Used to match leading and trailing whitespace. */
156-
var reTrim = /^\s+|\s+$/g,
157-
reTrimStart = /^\s+/,
158-
reTrimEnd = /\s+$/;
156+
/** Used to match leading whitespace. */
157+
var reTrimStart = /^\s+/;
158+
159+
/** Used to match a single whitespace character. */
160+
var reWhitespace = /\s/;
159161

160162
/** Used to match wrap detail comments. */
161163
var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
@@ -165,6 +167,18 @@
165167
/** Used to match words composed of alphanumeric characters. */
166168
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
167169

170+
/**
171+
* Used to validate the `validate` option in `_.template` variable.
172+
*
173+
* Forbids characters which could potentially change the meaning of the function argument definition:
174+
* - "()," (modification of function parameters)
175+
* - "=" (default value)
176+
* - "[]{}" (destructuring of function parameters)
177+
* - "/" (beginning of a comment)
178+
* - whitespace
179+
*/
180+
var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
181+
168182
/** Used to match backslashes in property paths. */
169183
var reEscapeChar = /\\(\\)?/g;
170184

@@ -993,6 +1007,19 @@
9931007
});
9941008
}
9951009

1010+
/**
1011+
* The base implementation of `_.trim`.
1012+
*
1013+
* @private
1014+
* @param {string} string The string to trim.
1015+
* @returns {string} Returns the trimmed string.
1016+
*/
1017+
function baseTrim(string) {
1018+
return string
1019+
? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
1020+
: string;
1021+
}
1022+
9961023
/**
9971024
* The base implementation of `_.unary` without support for storing metadata.
9981025
*
@@ -1326,6 +1353,21 @@
13261353
: asciiToArray(string);
13271354
}
13281355

1356+
/**
1357+
* Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
1358+
* character of `string`.
1359+
*
1360+
* @private
1361+
* @param {string} string The string to inspect.
1362+
* @returns {number} Returns the index of the last non-whitespace character.
1363+
*/
1364+
function trimmedEndIndex(string) {
1365+
var index = string.length;
1366+
1367+
while (index-- && reWhitespace.test(string.charAt(index))) {}
1368+
return index;
1369+
}
1370+
13291371
/**
13301372
* Used by `_.unescape` to convert HTML entities to characters.
13311373
*
@@ -12494,7 +12536,7 @@
1249412536
if (typeof value != 'string') {
1249512537
return value === 0 ? value : +value;
1249612538
}
12497-
value = value.replace(reTrim, '');
12539+
value = baseTrim(value);
1249812540
var isBinary = reIsBinary.test(value);
1249912541
return (isBinary || reIsOctal.test(value))
1250012542
? freeParseInt(value.slice(2), isBinary ? 2 : 8)
@@ -14866,6 +14908,12 @@
1486614908
if (!variable) {
1486714909
source = 'with (obj) {\n' + source + '\n}\n';
1486814910
}
14911+
// Throw an error if a forbidden character was found in `variable`, to prevent
14912+
// potential command injection attacks.
14913+
else if (reForbiddenIdentifierChars.test(variable)) {
14914+
throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
14915+
}
14916+
1486914917
// Cleanup code by stripping empty strings.
1487014918
source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
1487114919
.replace(reEmptyStringMiddle, '$1')
@@ -14979,7 +15027,7 @@
1497915027
function trim(string, chars, guard) {
1498015028
string = toString(string);
1498115029
if (string && (guard || chars === undefined)) {
14982-
return string.replace(reTrim, '');
15030+
return baseTrim(string);
1498315031
}
1498415032
if (!string || !(chars = baseToString(chars))) {
1498515033
return string;
@@ -15014,7 +15062,7 @@
1501415062
function trimEnd(string, chars, guard) {
1501515063
string = toString(string);
1501615064
if (string && (guard || chars === undefined)) {
15017-
return string.replace(reTrimEnd, '');
15065+
return string.slice(0, trimmedEndIndex(string) + 1);
1501815066
}
1501915067
if (!string || !(chars = baseToString(chars))) {
1502015068
return string;

0 commit comments

Comments
 (0)
Please sign in to comment.