Skip to content

Commit 83526fe

Browse files
committed
- Fix: Require json as "own" property
- Testing: Improve coverage
1 parent f6868d4 commit 83526fe

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.0.0 (2020-01-13)
44

55
- Breaking change: Expect Node >= 8
6+
- Fix: Require `json` as "own" property
67
- Fix: wrap: false returning inconsistent data types (@CacheControl)
78
- Fix: Ensure throwing with a bad result type
89
- Fix: Avoid erring when value before parent selector is falsey

src/jsonpath.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,13 +279,13 @@ JSONPath.prototype.evaluate = function (
279279
'argument to JSONPath.evaluate().'
280280
);
281281
}
282-
if (!('json' in expr)) {
282+
if (!(hasOwnProp.call(expr, 'json'))) {
283283
throw new TypeError(
284284
'You must supply a "json" property when providing an object ' +
285285
'argument to JSONPath.evaluate().'
286286
);
287287
}
288-
json = hasOwnProp.call(expr, 'json') ? expr.json : json;
288+
({json} = expr);
289289
flatten = hasOwnProp.call(expr, 'flatten') ? expr.flatten : flatten;
290290
this.currResultType = hasOwnProp.call(expr, 'resultType')
291291
? expr.resultType

test/test.api.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,26 @@ describe('JSONPath - API', function () {
7171
result = jp.evaluate();
7272
assert.deepEqual(result, expected);
7373
});
74+
75+
it('should test defaults with `evaluate` object and `autostart: false`', () => {
76+
const books = json.store.book;
77+
const expected = [books[0].author, books[1].author, books[2].author, books[3].author];
78+
const jp = jsonpath({
79+
autostart: false
80+
});
81+
const result = jp.evaluate({
82+
json,
83+
path: '$.store.book[*].author',
84+
sandbox: {category: 'reference'},
85+
preventEval: true,
86+
flatten: true,
87+
wrap: false,
88+
resultType: 'value',
89+
callback () { /* */ },
90+
parent: null,
91+
parentProperty: null,
92+
otherTypeCallback () { /* */ }
93+
});
94+
assert.deepEqual(result, expected);
95+
});
7496
});

0 commit comments

Comments
 (0)