mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 03:17:49 +00:00
Make _.escape escape backticks as well
In Internet Explorer ≤ 8, the backtick character can be used to break out of unquoted attribute values or HTML comments. See http://html5sec.org/#102, http://html5sec.org/#108, and http://html5sec.org/#133.
This commit is contained in:
15
lodash.js
15
lodash.js
@@ -40,8 +40,8 @@
|
|||||||
reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
|
reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
|
||||||
|
|
||||||
/** Used to match HTML entities and HTML characters */
|
/** Used to match HTML entities and HTML characters */
|
||||||
var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
|
var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
|
||||||
reUnescapedHtml = /[&<>"']/g;
|
reUnescapedHtml = /[&<>"'`]/g;
|
||||||
|
|
||||||
/** Used to match template delimiters */
|
/** Used to match template delimiters */
|
||||||
var reEscape = /<%-([\s\S]+?)%>/g,
|
var reEscape = /<%-([\s\S]+?)%>/g,
|
||||||
@@ -157,13 +157,19 @@
|
|||||||
* unless they're part of a tag or unquoted attribute value.
|
* unless they're part of a tag or unquoted attribute value.
|
||||||
* See [Mathias' article](http://mathiasbynens.be/notes/ambiguous-ampersands)
|
* See [Mathias' article](http://mathiasbynens.be/notes/ambiguous-ampersands)
|
||||||
* (under "semi-related fun fact") for more details.
|
* (under "semi-related fun fact") for more details.
|
||||||
|
*
|
||||||
|
* Backticks are escaped because in Internet Explorer <= 8, they can be used
|
||||||
|
* to break out of unquoted attribute values or HTML comments. See
|
||||||
|
* <http://html5sec.org/#102>, <http://html5sec.org/#108>, and
|
||||||
|
* <http://html5sec.org/#133> for more details.
|
||||||
*/
|
*/
|
||||||
var htmlEscapes = {
|
var htmlEscapes = {
|
||||||
'&': '&',
|
'&': '&',
|
||||||
'<': '<',
|
'<': '<',
|
||||||
'>': '>',
|
'>': '>',
|
||||||
'"': '"',
|
'"': '"',
|
||||||
"'": '''
|
"'": ''',
|
||||||
|
'`': '`'
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Used to convert HTML entities to characters */
|
/** Used to convert HTML entities to characters */
|
||||||
@@ -172,7 +178,8 @@
|
|||||||
'<': '<',
|
'<': '<',
|
||||||
'>': '>',
|
'>': '>',
|
||||||
'"': '"',
|
'"': '"',
|
||||||
''': "'"
|
''': "'",
|
||||||
|
'`': '`'
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2372,8 +2372,8 @@
|
|||||||
QUnit.module('lodash.escape');
|
QUnit.module('lodash.escape');
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var escaped = '&<>"'\/',
|
var escaped = '&<>"'`\/',
|
||||||
unescaped = '&<>"\'\/';
|
unescaped = '&<>"\'`\/';
|
||||||
|
|
||||||
test('should escape values', 1, function() {
|
test('should escape values', 1, function() {
|
||||||
strictEqual(_.escape(unescaped), escaped);
|
strictEqual(_.escape(unescaped), escaped);
|
||||||
|
|||||||
Reference in New Issue
Block a user