From 2036ccd68bd2232e4201c188c5f6a5cf563fb3e9 Mon Sep 17 00:00:00 2001 From: Henrik Hjelte Date: Thu, 3 Jul 2008 01:36:51 +0200 Subject: [PATCH] Testcase and bugfix for ticket-86 eval script with html comments --- src/array.js | 32 +++++----- src/prototype.js | 13 ++-- test/unit/string_test.js | 152 ++++++++++++++++++++++++---------------------- 3 files changed, 101 insertions(+), 96 deletions(-) diff --git a/src/array.js b/src/array.js index 1706192..6c3ff24 100644 --- a/src/array.js +++ b/src/array.js @@ -28,48 +28,48 @@ Object.extend(Array.prototype, { for (var i = 0, length = this.length; i < length; i++) iterator(this[i]); }, - + clear: function() { this.length = 0; return this; }, - + first: function() { return this[0]; }, - + last: function() { return this[this.length - 1]; }, - + compact: function() { return this.select(function(value) { return value != null; }); }, - + flatten: function() { return this.inject([], function(array, value) { return array.concat(Object.isArray(value) ? value.flatten() : [value]); }); }, - + without: function() { var values = $A(arguments); return this.select(function(value) { return !values.include(value); }); }, - + reverse: function(inline) { return (inline !== false ? this : this.toArray())._reverse(); }, - + reduce: function() { return this.length > 1 ? this : this[0]; }, - + uniq: function(sorted) { return this.inject([], function(array, value, index) { if (0 == index || (sorted ? array.last() != value : !array.include(value))) @@ -77,7 +77,7 @@ Object.extend(Array.prototype, { return array; }); }, - + intersect: function(array) { var length = array.length, i; return this.uniq().findAll(function(item) { @@ -86,19 +86,19 @@ Object.extend(Array.prototype, { return false; }); }, - + clone: function() { return [].concat(this); }, - + size: function() { return this.length; }, - + inspect: function() { return '[' + this.map(Object.inspect).join(', ') + ']'; }, - + toJSON: function() { var results = []; this.each(function(object) { @@ -142,9 +142,9 @@ if (Prototype.Browser.Opera){ for (var i = 0, length = this.length; i < length; i++) array.push(this[i]); for (var i = 0, length = arguments.length; i < length; i++) { if (Object.isArray(arguments[i])) { - for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++) + for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++) array.push(arguments[i][j]); - } else { + } else { array.push(arguments[i]); } } diff --git a/src/prototype.js b/src/prototype.js index 024f774..1975d9e 100644 --- a/src/prototype.js +++ b/src/prototype.js @@ -2,7 +2,7 @@ var Prototype = { Version: '<%= PROTOTYPE_VERSION %>', - + Browser: { IE: !!(window.attachEvent && !window.opera), Opera: !!window.opera, @@ -15,22 +15,21 @@ var Prototype = { XPath: !!document.evaluate, SelectorsAPI: !!document.querySelector, ElementExtensions: !!window.HTMLElement, - SpecificElementExtensions: + SpecificElementExtensions: document.createElement('div')['__proto__'] && - document.createElement('div')['__proto__'] !== + document.createElement('div')['__proto__'] !== document.createElement('form')['__proto__'] }, + ScriptFragment: ']*>(?:\\s*\\s*)*<\/script>', + JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/, - ScriptFragment: ']*>([^\\x00]*?)<\/script>', - JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/, - emptyFunction: function() { }, K: function(x) { return x } }; if (Prototype.Browser.MobileSafari) Prototype.BrowserFeatures.SpecificElementExtensions = false; - + <%= include 'base.js', 'string.js' %> diff --git a/test/unit/string_test.js b/test/unit/string_test.js index c4e21f0..772962c 100644 --- a/test/unit/string_test.js +++ b/test/unit/string_test.js @@ -16,7 +16,7 @@ new Test.Unit.Runner({ testGsubWithReplacementFunction: function() { var source = 'foo boo boz'; - + this.assertEqual('Foo Boo BoZ', source.gsub(/[^o]+/, function(match) { return match[0].toUpperCase() @@ -31,24 +31,24 @@ new Test.Unit.Runner({ })); }, - + testGsubWithReplacementString: function() { var source = 'foo boo boz'; - + this.assertEqual('foobooboz', source.gsub(/\s+/, '')); - this.assertEqual(' z', + this.assertEqual(' z', source.gsub(/(.)(o+)/, '')); - - this.assertEqual('ウィメンズ2007
クルーズコレクション', + + this.assertEqual('ウィメンズ2007
クルーズコレクション', 'ウィメンズ2007\nクルーズコレクション'.gsub(/\n/,'
')); - this.assertEqual('ウィメンズ2007
クルーズコレクション', + this.assertEqual('ウィメンズ2007
クルーズコレクション', 'ウィメンズ2007\nクルーズコレクション'.gsub('\n','
')); }, - + testGsubWithReplacementTemplateString: function() { var source = 'foo boo boz'; - + this.assertEqual('-oo-#{1}- -oo-#{1}- -o-#{1}-z', source.gsub(/(.)(o+)/, '-#{2}-\\#{1}-')); this.assertEqual('-foo-f- -boo-b- -bo-b-z', @@ -56,9 +56,9 @@ new Test.Unit.Runner({ this.assertEqual('-oo-f- -oo-b- -o-b-z', source.gsub(/(.)(o+)/, '-#{2}-#{1}-')); this.assertEqual(' z', - source.gsub(/(.)(o+)/, '#{3}')); + source.gsub(/(.)(o+)/, '#{3}')); }, - + testSubWithReplacementFunction: function() { var source = 'foo boo boz'; @@ -79,10 +79,10 @@ new Test.Unit.Runner({ return match[0].toUpperCase() }, -1), -1); }, - + testSubWithReplacementString: function() { var source = 'foo boo boz'; - + this.assertEqual('oo boo boz', source.sub(/[^o]+/, '')); this.assertEqual('oooo boz', @@ -92,7 +92,7 @@ new Test.Unit.Runner({ this.assertEqual('-f-oo- b-oo boz', source.sub(/[^o]+/, '-#{0}-', 2)); }, - + testScan: function() { var source = 'foo boo boz', results = []; var str = source.scan(/[o]+/, function(match) { @@ -102,7 +102,7 @@ new Test.Unit.Runner({ this.assertEqual(source, source.scan(/x/, this.fail)); this.assert(typeof str == 'string'); }, - + testToArray: function() { this.assertEnumEqual([],''.toArray()); this.assertEnumEqual(['a'],'a'.toArray()); @@ -110,7 +110,7 @@ new Test.Unit.Runner({ this.assertEnumEqual(['f','o','o'],'foo'.toArray()); }, - /* + /* Note that camelize() differs from its Rails counterpart, as it is optimized for dealing with JavaScript object properties in conjunction with CSS property names: @@ -124,14 +124,14 @@ new Test.Unit.Runner({ this.assertEqual('foo_bar', 'foo_bar'.camelize()); this.assertEqual('FooBar', '-foo-bar'.camelize()); this.assertEqual('FooBar', 'FooBar'.camelize()); - + this.assertEqual('fooBar', 'foo-bar'.camelize()); this.assertEqual('borderBottomWidth', 'border-bottom-width'.camelize()); - + this.assertEqual('classNameTest','class-name-test'.camelize()); this.assertEqual('classNameTest','className-test'.camelize()); this.assertEqual('classNameTest','class-nameTest'.camelize()); - + /* this.benchmark(function(){ 'class-name-test'.camelize(); },10000); */ @@ -145,8 +145,8 @@ new Test.Unit.Runner({ this.assertEqual('Hello','HELLO'.capitalize()); this.assertEqual('Hello','Hello'.capitalize()); this.assertEqual('Hello world','hello WORLD'.capitalize()); - }, - + }, + testUnderscore: function() { this.assertEqual('', ''.underscore()); this.assertEqual('_', '-'.underscore()); @@ -155,9 +155,9 @@ new Test.Unit.Runner({ this.assertEqual('foo_bar', 'foo_bar'.underscore()); this.assertEqual('border_bottom', 'borderBottom'.underscore()); this.assertEqual('border_bottom_width', 'borderBottomWidth'.underscore()); - this.assertEqual('border_bottom_width', 'border-Bottom-Width'.underscore()); + this.assertEqual('border_bottom_width', 'border-Bottom-Width'.underscore()); }, - + testDasherize: function() { this.assertEqual('', ''.dasherize()); this.assertEqual('foo', 'foo'.dasherize()); @@ -165,25 +165,25 @@ new Test.Unit.Runner({ this.assertEqual('foo-bar', 'foo-bar'.dasherize()); this.assertEqual('border-bottom-width', 'border_bottom_width'.dasherize()); }, - + testTruncate: function() { var source = 'foo boo boz foo boo boz foo boo boz foo boo boz'; this.assertEqual(source, source.truncate(source.length)); this.assertEqual('foo boo boz foo boo boz foo...', source.truncate(0)); this.assertEqual('fo...', source.truncate(5)); this.assertEqual('foo b', source.truncate(5, '')); - + this.assert(typeof 'foo'.truncate(5) == 'string'); this.assert(typeof 'foo bar baz'.truncate(5) == 'string'); }, - + testStrip: function() { this.assertEqual('hello world', ' hello world '.strip()); this.assertEqual('hello world', 'hello world'.strip()); this.assertEqual('hello \n world', ' hello \n world '.strip()); this.assertEqual('', ' '.strip()); }, - + testStripTags: function() { this.assertEqual('hello world', 'hello world'.stripTags()); this.assertEqual('hello world', 'hello world'.stripTags()); @@ -191,86 +191,92 @@ new Test.Unit.Runner({ this.assertEqual('hello world', 'hello world'.stripTags()); this.assertEqual('1\n2', '1\n2'.stripTags()); }, - + testStripScripts: function() { this.assertEqual('foo bar', 'foo bar'.stripScripts()); this.assertEqual('foo bar', ('foo