Skip to content

Commit 028525a

Browse files
committed
[Tests] skip Object.create tests when null objects are not available.
Also, “plain object” is not a term that exists outside this lib; so begin the move to the term “null object”.
1 parent 335f839 commit 028525a

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ assert.deepEqual(qs.parse('foo[bar]=baz'), {
3939
});
4040
```
4141

42-
When using the `plainObjects` option the parsed value is returned as a plain object, created via `Object.create(null)` and as such you should be aware that prototype methods will not exist on it and a user may set those names to whatever value they like:
42+
When using the `plainObjects` option the parsed value is returned as a null object, created via `Object.create(null)` and as such you should be aware that prototype methods will not exist on it and a user may set those names to whatever value they like:
4343

4444
```javascript
45-
var plainObject = qs.parse('a[hasOwnProperty]=b', { plainObjects: true });
46-
assert.deepEqual(plainObject, { a: { hasOwnProperty: 'b' } });
45+
var nullObject = qs.parse('a[hasOwnProperty]=b', { plainObjects: true });
46+
assert.deepEqual(nullObject, { a: { hasOwnProperty: 'b' } });
4747
```
4848

4949
By default parameters that would overwrite properties on the object prototype are ignored, if you wish to keep the data from those fields either use `plainObjects` as mentioned above, or set `allowPrototypes` to `true` which will allow user input to overwrite those properties. *WARNING* It is generally a bad idea to enable this option as it can cause problems when attempting to use the properties that have been overwritten. Always be careful with this option.

test/parse.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ test('parse()', function (t) {
379379
st.end();
380380
});
381381

382-
t.test('parses plain objects correctly', function (st) {
382+
t.test('parses null objects correctly', { skip: !Object.create }, function (st) {
383383
var a = Object.create(null);
384384
a.b = 'c';
385385

@@ -408,7 +408,7 @@ test('parse()', function (t) {
408408
st.end();
409409
});
410410

411-
t.test('can return plain objects', function (st) {
411+
t.test('can return null objects', { skip: !Object.create }, function (st) {
412412
var expected = Object.create(null);
413413
expected.a = Object.create(null);
414414
expected.a.b = 'c';

test/stringify.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test('stringify()', function (t) {
126126
st.end();
127127
});
128128

129-
t.test('stringifies an empty object', function (st) {
129+
t.test('stringifies a null object', { skip: !Object.create }, function (st) {
130130
var obj = Object.create(null);
131131
obj.a = 'b';
132132
st.equal(qs.stringify(obj), 'a=b');
@@ -141,10 +141,8 @@ test('stringify()', function (t) {
141141
st.end();
142142
});
143143

144-
t.test('stringifies an object with an empty object as a child', function (st) {
145-
var obj = {
146-
a: Object.create(null)
147-
};
144+
t.test('stringifies an object with a null object as a child', { skip: !Object.create }, function (st) {
145+
var obj = { a: Object.create(null) };
148146

149147
obj.a.b = 'c';
150148
st.equal(qs.stringify(obj), 'a%5Bb%5D=c');

0 commit comments

Comments
 (0)