mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Make _.escape match _.template's escape delimiter results for null and undefined values.
Former-commit-id: b6717c6debf3bc308cf12b778916f5a46dbb954d
This commit is contained in:
@@ -202,8 +202,8 @@
|
|||||||
// http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
|
// http://code.google.com/closure/compiler/docs/api-tutorial3.html#export
|
||||||
source = source.replace(RegExp('\\.(' + propWhitelist.join('|') + ')\\b', 'g'), "['$1']");
|
source = source.replace(RegExp('\\.(' + propWhitelist.join('|') + ')\\b', 'g'), "['$1']");
|
||||||
|
|
||||||
// remove brackets from `_.escape(__t)` in `tokenizeEscape`
|
// remove brackets from `_.escape()` in `tokenizeEscape`
|
||||||
source = source.replace("_['escape'](__t)", '_.escape(__t)');
|
source = source.replace("_['escape'](\"", '_.escape("');
|
||||||
|
|
||||||
// remove whitespace from string literals
|
// remove whitespace from string literals
|
||||||
source = source.replace(/'(?:(?=(\\?))\1.)*?'/g, function(string) {
|
source = source.replace(/'(?:(?=(\\?))\1.)*?'/g, function(string) {
|
||||||
|
|||||||
@@ -525,7 +525,7 @@
|
|||||||
*/
|
*/
|
||||||
function tokenizeEscape(match, value) {
|
function tokenizeEscape(match, value) {
|
||||||
var index = tokenized.length;
|
var index = tokenized.length;
|
||||||
tokenized[index] = "'+\n((__t = (" + value + ")) == null ? '' : _.escape(__t)) +\n'";
|
tokenized[index] = "'+\n_.escape(" + value + ") +\n'";
|
||||||
return token + index;
|
return token + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2985,7 +2985,7 @@
|
|||||||
* // => "Curly, Larry & Moe"
|
* // => "Curly, Larry & Moe"
|
||||||
*/
|
*/
|
||||||
function escape(string) {
|
function escape(string) {
|
||||||
return (string + '').replace(reUnescapedHtml, escapeHtmlChar);
|
return string == null ? '' : (string + '').replace(reUnescapedHtml, escapeHtmlChar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -157,6 +157,11 @@
|
|||||||
test('should not escape the "/" character', function() {
|
test('should not escape the "/" character', function() {
|
||||||
equal(_.escape('/'), '/');
|
equal(_.escape('/'), '/');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should return empty string when passed `null` or `undefined`', function() {
|
||||||
|
equal(_.escape(null), '');
|
||||||
|
equal(_.escape(undefined), '');
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user