// ========================================================================== // Project: SproutCore
- JavaScript Application Framework // Copyright: ©2011 Apple Inc. All rights reserved. // License: Licensed under MIT license (see license.js) // ==========================================================================
/*global module test equals context */ module(“Render Context–Escaping HTML”); test(“Escaping HTML”, function() {
var input = "<p>HTML!</p><script>alert('hi');<" + "/script> & Hello, World!"; var output = SC.RenderContext.escapeHTML(input); equals(output, '<p>HTML!</p><script>alert(\'hi\');</script> & Hello, World!', "Properly escapes HTML");
});
module(“Render Context–Escaping , preserve HTML entities like '”); test(“Escaping HTML, preserve HTML entities”, function() {
var input = "<p>HTML!</p><script>alert('hi');<" + "/script> &illegalese; & & Hello, World!"; var output = SC.RenderContext.escapeHTML(input); equals(output, '<p>HTML!</p><script>alert(\'hi\');</script> &illegalese; & & Hello, World!', "Properly escapes HTML");
});
test(“Tests stolen from Prototype.js”, function() {
var largeTextEscaped = '<span>test</span>', largeTextUnescaped = '<span>test</span>'; for (var i = 0; i < 2048; i++) { largeTextEscaped += ' ABC'; largeTextUnescaped += ' ABC'; } var tests = [ 'foo bar', 'foo bar', 'foo <span>bar</span>', 'foo <span>bar</span>', 'foo ß bar', 'foo ß bar', 'ウィメンズ2007\nクルーズコレクション', 'ウィメンズ2007\nクルーズコレクション', 'a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g', 'a<a href="blah">blub</a>b<span><div></div></span>cdef<strong>!!!!</strong>g', '1\n2', '1\n2', largeTextUnescaped, largeTextEscaped ]; for (var idx = 0; idx < tests.length; idx++) { // some of these strings are REALLY LONG so we don't want to write them out ok(SC.RenderContext.escapeHTML(tests[idx++]) === tests[idx]); }
});
test(“Should accept number argument”, function() {
var number = 12345.6789, numStr = number.toString(); equals(numStr, SC.RenderContext.escapeHTML(number), "Properly produces string when invoked with a number argument");
});