diff --git a/CHANGELOG b/CHANGELOG index 28602c9..f9915da 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Remove sniffing when branching `escapeHTML` and `unescapeHTML`. [#570 state:resolved] (kangax) + * Redefine Element#down in IE 6-7 to avoid extending all descendants when no selector is given. [#452 state:resolved] (eno, Andrew Dupont) * Reverse the definitions of Event#pointer(X|Y) and Event#pointer to prevent unnecessary computation. [#403 state:resolved] (Nick Stakenburg, Andrew Dupont) diff --git a/src/lang/string.js b/src/lang/string.js index beaad09..90c2ea6 100644 --- a/src/lang/string.js +++ b/src/lang/string.js @@ -176,7 +176,7 @@ Object.extend(String.prototype, (function() { * Strips tags and converts the entity forms of special HTML characters to their normal form. **/ function unescapeHTML() { - var div = new Element('div'); + var div = document.createElement('div'); div.innerHTML = this.stripTags(); return div.childNodes[0] ? (div.childNodes.length > 1 ? $A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) : @@ -437,15 +437,6 @@ Object.extend(String.prototype, (function() { }; })()); -if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, { - escapeHTML: function() { - return this.replace(/&/g,'&').replace(//g,'>'); - }, - unescapeHTML: function() { - return this.stripTags().replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&'); - } -}); - Object.extend(String.prototype.escapeHTML, { div: document.createElement('div'), text: document.createTextNode('') @@ -453,3 +444,14 @@ Object.extend(String.prototype.escapeHTML, { String.prototype.escapeHTML.div.appendChild(String.prototype.escapeHTML.text); +if ('<\n'.escapeHTML() !== '<\n') { + String.prototype.escapeHTML = function() { + return this.replace(/&/g,'&').replace(//g,'>'); + } +} + +if ('<\n'.unescapeHTML() !== '<\n') { + String.prototype.unescapeHTML = function() { + return this.stripTags().replace(/</g,'<').replace(/>/g,'>').replace(/&/g,'&'); + } +} \ No newline at end of file