diff --git a/CHANGELOG.md b/CHANGELOG.md index 73c8610..c176e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ ## [Unreleased] +## [0.0.2] - 2020-09-01 +### Fixed +- Last element of array was not selected (regression #1) + ## [0.0.1] - 2020-08-03 ### Added - Filters @@ -37,7 +41,8 @@ ### Added - Basic design draft -[Unreleased]: https://github.com/f3ath/jessie/compare/0.0.1...HEAD +[Unreleased]: https://github.com/f3ath/jessie/compare/0.0.2...HEAD +[0.0.2]: https://github.com/f3ath/jessie/compare/0.0.1...0.0.2 [0.0.1]: https://github.com/f3ath/jessie/compare/0.0.0+dev.7...0.0.1 [0.0.0+dev.7]: https://github.com/f3ath/jessie/compare/0.0.0+dev.6...0.0.0+dev.7 [0.0.0+dev.6]: https://github.com/f3ath/jessie/compare/0.0.0+dev.5...0.0.0+dev.6 diff --git a/lib/src/selector/index.dart b/lib/src/selector/index.dart index 83b2fe1..0845d5e 100644 --- a/lib/src/selector/index.dart +++ b/lib/src/selector/index.dart @@ -9,7 +9,7 @@ class Index with SelectorMixin { @override Iterable filter(Iterable results) => results - .where((r) => r.value is List && r.value.length > index + 1) + .where((r) => r.value is List && r.value.length > index) .map((r) => Result(r.value[index], r.path + expression())); @override diff --git a/pubspec.yaml b/pubspec.yaml index 0c3c142..c686e9b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: json_path -version: 0.0.1 +version: 0.0.2 description: JSONPath for Dart. JSONPath is XPath for JSON. It is a path in a JSON document. homepage: "https://github.com/f3ath/jessie" diff --git a/test/json_path_test.dart b/test/json_path_test.dart index caaec1c..e56db11 100644 --- a/test/json_path_test.dart +++ b/test/json_path_test.dart @@ -264,6 +264,13 @@ void main() { expect(path.filter(json).single.path, r"$['store']['book'][0]['title']"); }); + test('Last element of array (regression #1)', () { + final path = JsonPath(r"$['store']['book'][3]['price']"); + expect(path.toString(), r"$['store']['book'][3]['price']"); + expect(path.filter(json).single.value, 22.99); + expect(path.filter(json).single.path, r"$['store']['book'][3]['price']"); + }); + test('All in list', () { final path = JsonPath(r'$.store.book[*]'); expect(path.toString(), r"$['store']['book'][*]");