From 643b7bec37e6525a3bbddba8ee904a4259911a16 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 24 Apr 2007 02:50:52 +0000 Subject: [PATCH] prototype: Add extra spacing so Array#toJSON and Hash#toJSON generate YAML-loadable JSON. Closes #7883. --- CHANGELOG | 2 ++ src/array.js | 2 +- src/base.js | 4 ++-- src/hash.js | 4 ++-- test/unit/array.html | 4 ++-- test/unit/base.html | 22 +++++++++++----------- test/unit/hash.html | 2 +- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index aa4d862..68201a1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add extra spacing so Array#toJSON and Hash#toJSON generate YAML-loadable JSON. Closes #7883. [Andrew Dupont] + * Fix Form.request for forms containing an input element with name="action". Closes #8063. [Thomas Fuchs, Mislav Marohnić] * Make Event.element extend the returned element. Closes #7870. [Thomas Fuchs] diff --git a/src/array.js b/src/array.js index feb592f..0abf72e 100644 --- a/src/array.js +++ b/src/array.js @@ -109,7 +109,7 @@ Object.extend(Array.prototype, { var value = Object.toJSON(object); if (value !== undefined) results.push(value); }); - return '[' + results.join(',') + ']'; + return '[' + results.join(', ') + ']'; } }); diff --git a/src/base.js b/src/base.js index f1ffac8..f005713 100644 --- a/src/base.js +++ b/src/base.js @@ -42,9 +42,9 @@ Object.extend(Object, { for (var property in object) { var value = Object.toJSON(object[property]); if (value !== undefined) - results.push(property.toJSON() + ':' + value); + results.push(property.toJSON() + ': ' + value); } - return '{' + results.join(',') + '}'; + return '{' + results.join(', ') + '}'; }, keys: function(object) { diff --git a/src/hash.js b/src/hash.js index 8bd09fe..5cbc30c 100644 --- a/src/hash.js +++ b/src/hash.js @@ -28,9 +28,9 @@ Object.extend(Hash, { var results = []; this.prototype._each.call(object, function(pair) { var value = Object.toJSON(pair.value); - if (value !== undefined) results.push(pair.key.toJSON() + ':' + value); + if (value !== undefined) results.push(pair.key.toJSON() + ': ' + value); }); - return '{' + results.join(',') + '}'; + return '{' + results.join(', ') + '}'; } }); diff --git a/test/unit/array.html b/test/unit/array.html index bb5c418..38d7101 100644 --- a/test/unit/array.html +++ b/test/unit/array.html @@ -123,8 +123,8 @@ testToJSON: function(){ with(this) { assertEqual('[]', [].toJSON()); assertEqual('[\"a\"]', ['a'].toJSON()); - assertEqual('[\"a\",1]', ['a', 1].toJSON()); - assertEqual('[\"a\",{\"b\":null}]', ['a', {'b': null}].toJSON()); + assertEqual('[\"a\", 1]', ['a', 1].toJSON()); + assertEqual('[\"a\", {\"b\": null}]', ['a', {'b': null}].toJSON()); }}, testReduce: function(){ with(this) { diff --git a/test/unit/base.html b/test/unit/base.html index 4dc1cf8..363bede 100644 --- a/test/unit/base.html +++ b/test/unit/base.html @@ -84,7 +84,7 @@ methodWithBindArgumentsAndArguments.bind({hi:'withBindArgsAndArgs'},'arg1','arg2')('arg3','arg4'); assertEqual('withBindArgsAndArgs,arg1,arg2,arg3,arg4', globalBindTest); }}, - + testObjectInspect: function() { with(this) { assertEqual('undefined', Object.inspect()); assertEqual('undefined', Object.inspect(undefined)); @@ -99,14 +99,14 @@ assertEqual('\"\"', Object.toJSON('')); assertEqual('[]', Object.toJSON([])); assertEqual('[\"a\"]', Object.toJSON(['a'])); - assertEqual('[\"a\",1]', Object.toJSON(['a', 1])); - assertEqual('[\"a\",{\"b\":null}]', Object.toJSON(['a', {'b': null}])); - assertEqual('{\"a\":\"hello!\"}', Object.toJSON({a: 'hello!'})); + assertEqual('[\"a\", 1]', Object.toJSON(['a', 1])); + assertEqual('[\"a\", {\"b\": null}]', Object.toJSON(['a', {'b': null}])); + assertEqual('{\"a\": \"hello!\"}', Object.toJSON({a: 'hello!'})); assertEqual('{}', Object.toJSON({})); assertEqual('{}', Object.toJSON({a: undefined, b: undefined, c: Prototype.K})); - assertEqual('{\"b\":[false,true],\"c\":{\"a\":\"hello!\"}}', + assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', Object.toJSON({'b': [undefined, false, true, undefined], c: {a: 'hello!'}})); - assertEqual('{\"b\":[false,true],\"c\":{\"a\":\"hello!\"}}', + assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', Object.toJSON($H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}))); assertEqual('true', Object.toJSON(true)); assertEqual('false', Object.toJSON(false)); @@ -148,12 +148,12 @@ div.setAttribute('id','test-'+i); document.body.appendChild(div); var tobj = new TestObj(); - var eventTest = {test:true}; + var eventTest = { test: true }; var call = tobj.assertingEventHandler.bindAsEventListener(tobj, - this.assertEqual.bind(this,eventTest), - this.assertEqual.bind(this,arg1), - this.assertEqual.bind(this,arg2), - this.assertEqual.bind(this,arg3), arg1, arg2, arg3 ); + this.assertEqual.bind(this, eventTest), + this.assertEqual.bind(this, arg1), + this.assertEqual.bind(this, arg2), + this.assertEqual.bind(this, arg3), arg1, arg2, arg3 ); call(eventTest); } }, diff --git a/test/unit/hash.html b/test/unit/hash.html index de83338..50dd0fe 100644 --- a/test/unit/hash.html +++ b/test/unit/hash.html @@ -133,7 +133,7 @@ }}, testToJSON: function(){ with(this) { - assertEqual('{\"b\":[false,true],\"c\":{\"a\":\"hello!\"}}', + assertEqual('{\"b\": [false, true], \"c\": {\"a\": \"hello!\"}}', $H({'b': [undefined, false, true, undefined], c: {a: 'hello!'}}).toJSON()); assertEqual('E', eval('(' + $H(Fixtures.dangerous).toJSON() + ')')._each);