Prototype: clean (un)escapeHTML IE special casing and optimize speed for IE and Safari
This commit is contained in:
parent
9a7dcd54fb
commit
c0509c7f5f
@ -1,6 +1,6 @@
|
||||
*SVN*
|
||||
|
||||
* Prevent linefeed normalisation in String.prototype.escapeHTML and unescapeHTML on IE for consistency with other browsers. [Thomas Fuchs]
|
||||
* Prevent linefeed normalisation in String.prototype.escapeHTML and unescapeHTML on IE for consistency with other browsers. Speed optimizations for Safari and IE. [Thomas Fuchs]
|
||||
|
||||
* Make Hash.toQueryString serialize undefined values. Ensure consistency with String.prototype.toQueryParams. Closes #7806. [Mislav Marohnić]
|
||||
Examples:
|
||||
|
2
src/prototype.js
vendored
2
src/prototype.js
vendored
@ -18,8 +18,6 @@ var Prototype = {
|
||||
},
|
||||
|
||||
ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
|
||||
LinefeedFragment: '-PrOtOtYpE LiNeFeEd-',
|
||||
|
||||
emptyFunction: function() {},
|
||||
K: function(x) { return x }
|
||||
}
|
||||
|
@ -193,18 +193,12 @@ Object.extend(String.prototype, {
|
||||
}
|
||||
});
|
||||
|
||||
if (Prototype.Browser.IE) Object.extend(String.prototype, {
|
||||
if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
|
||||
escapeHTML: function() {
|
||||
var self = arguments.callee;
|
||||
self.text.data = this.gsub(/\n/, Prototype.LinefeedFragment);
|
||||
return self.div.innerHTML.gsub(Prototype.LinefeedFragment, '\n');
|
||||
return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
},
|
||||
unescapeHTML: function() {
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = this.stripTags().gsub(/\n/, Prototype.LinefeedFragment);
|
||||
return (div.childNodes[0] ? (div.childNodes.length > 1 ?
|
||||
$A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :
|
||||
div.childNodes[0].nodeValue) : '').gsub(Prototype.LinefeedFragment, '\n');
|
||||
return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -266,6 +266,10 @@
|
||||
assertEqual(largeTextEscaped, largeTextUnescaped.escapeHTML());
|
||||
|
||||
assertEqual('1\n2', '1\n2'.escapeHTML());
|
||||
|
||||
benchmark(function(){
|
||||
largeTextUnescaped.escapeHTML();
|
||||
},1000);
|
||||
}},
|
||||
|
||||
testUnescapeHTML: function() {with(this) {
|
||||
@ -279,6 +283,11 @@
|
||||
assertEqual(largeTextUnescaped, largeTextEscaped.unescapeHTML());
|
||||
|
||||
assertEqual('1\n2', '1\n2'.unescapeHTML());
|
||||
|
||||
benchmark(function(){
|
||||
largeTextEscaped.unescapeHTML();
|
||||
},1000);
|
||||
|
||||
}},
|
||||
|
||||
testTemplateEvaluation: function() {with(this) {
|
||||
|
Loading…
Reference in New Issue
Block a user