Skip to content

Commit

Permalink
v0.6.2 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath authored Jul 22, 2023
1 parent bb7301e commit ba70f05
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 15 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.6.2] - 2023-07-21
### Fixed
- Disallow comparison of non-singular queries

## [0.6.1] - 2023-07-17
### Fixed
- Allow namespace in between selector segments

## [0.6.0] - 2023-05-27
### Changed
- Bump SDK version to 3.0.0
- Disallow whitespace between a function name and the parentheses
- Disallow whitespace between an expression and the brackets
- Disallow whitespace between the function name and the parentheses
- Disallow whitespace between the expression and the brackets
- `search()` and `match()` now strictly follow the I-Regexp convention. Expressions not conforming to I-Regexp will yield `false` regardless of the value

## [0.5.3] - 2023-04-29 \[YANKED\]
Expand Down Expand Up @@ -156,6 +160,7 @@ Previously, no modification would be made and no errors/exceptions thrown.
### Added
- Basic design draft

[0.6.2]: https://github.com/f3ath/jessie/compare/0.6.1...0.6.2
[0.6.1]: https://github.com/f3ath/jessie/compare/0.6.0...0.6.1
[0.6.0]: https://github.com/f3ath/jessie/compare/0.5.3...0.6.0
[0.5.3]: https://github.com/f3ath/jessie/compare/0.5.2...0.5.3
Expand Down
4 changes: 1 addition & 3 deletions lib/src/grammar/dot_name.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:json_path/src/grammar/strings.dart';
import 'package:json_path/src/grammar/wildcard.dart';
import 'package:petitparser/petitparser.dart';

final dotName =
[memberNameShorthand, wildcard].toChoiceParser().skip(before: char('.'));
final dotName = memberNameShorthand.skip(before: char('.'));
3 changes: 2 additions & 1 deletion lib/src/grammar/json_path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class JsonPathGrammarDefinition extends GrammarDefinition<Expression<Nodes>> {
_unionElement().toList().inBrackets().map(unionSelector);

Parser<Selector> _singularUnion() =>
_singularUnionElement().toList().inBrackets().map(unionSelector);
_singularUnionElement().toSingularList().inBrackets().map(unionSelector);

Parser<Selector> _recursion() => [
wildcard,
Expand Down Expand Up @@ -127,6 +127,7 @@ class JsonPathGrammarDefinition extends GrammarDefinition<Expression<Nodes>> {

Parser<Selector> _segment() => [
dotName,
wildcard.skip(before: char('.')),
ref0(_union),
ref0(_recursion),
].toChoiceParser().trim();
Expand Down
3 changes: 3 additions & 0 deletions lib/src/grammar/parser_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ extension ParserExt<R> on Parser<R> {
skip(before: (separator ?? char(',')).trim()).star()
].toSequenceParser().map<List<R>>((v) => v.expand<R>((e) => e).toList());

/// Makes a list consisting of a single element.
Parser<List<R>> toSingularList() => map((v) => [v]);

/// Same in parenthesis.
Parser<R> inParens() => skip(before: char('('), after: char(')'));

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: json_path
version: 0.6.1
version: 0.6.2
description: Implementation of JSONPath expressions like "$.store.book[2].price". Reads and writes values in parsed JSON objects.
homepage: "https://github.com/f3ath/jessie"

Expand Down
2 changes: 1 addition & 1 deletion test/cases/cts
120 changes: 120 additions & 0 deletions test/cases/standard/expressions_equality.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,126 @@
"selector": "$[?(@.foo != @.bar)]",
"document": [{"foo": 1, "bar": 2}, {"foo": 42, "bar": 42}, {"foo": 1, "bro": 1}, {}],
"result": [{"foo": 1, "bar": 2}, {"foo": 1, "bro": 1}]
}, {
"name": "relative non-singular query, index, equal",
"selector": "$[?(@[0, 0]==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, index, not equal",
"selector": "$[?(@[0, 0]!=42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, index, less-or-equal",
"selector": "$[?(@[0, 0]==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, name, equal",
"selector": "$[?(@['a', 'a']==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, name, not equal",
"selector": "$[?(@['a', 'a']!=42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, name, less-or-equal",
"selector": "$[?(@['a', 'a']==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, combined, equal",
"selector": "$[?(@[0, '0']==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, combined, not equal",
"selector": "$[?(@[0, '0']!=42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, combined, less-or-equal",
"selector": "$[?(@[0, '0']==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, wildcard, equal",
"selector": "$[?(@.*==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, wildcard, not equal",
"selector": "$[?(@.*!=42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, wildcard, less-or-equal",
"selector": "$[?(@.*==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, slice, equal",
"selector": "$[?(@[0:0]==42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, slice, not equal",
"selector": "$[?(@[0:0]!=42)]",
"invalid_selector": true
}, {
"name": "relative non-singular query, slice, less-or-equal",
"selector": "$[?(@[0:0]==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, index, equal",
"selector": "$[?($[0, 0]==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, index, not equal",
"selector": "$[?($[0, 0]!=42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, index, less-or-equal",
"selector": "$[?($[0, 0]==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, name, equal",
"selector": "$[?($['a', 'a']==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, name, not equal",
"selector": "$[?($['a', 'a']!=42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, name, less-or-equal",
"selector": "$[?($['a', 'a']==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, combined, equal",
"selector": "$[?($[0, '0']==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, combined, not equal",
"selector": "$[?($[0, '0']!=42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, combined, less-or-equal",
"selector": "$[?($[0, '0']==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, wildcard, equal",
"selector": "$[?($.*==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, wildcard, not equal",
"selector": "$[?($.*!=42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, wildcard, less-or-equal",
"selector": "$[?($.*==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, slice, equal",
"selector": "$[?($[0:0]==42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, slice, not equal",
"selector": "$[?($[0:0]!=42)]",
"invalid_selector": true
}, {
"name": "absolute non-singular query, slice, less-or-equal",
"selector": "$[?($[0:0]==42)]",
"invalid_selector": true
}
]
}
52 changes: 52 additions & 0 deletions test/cases/standard/whitespace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"tests": [
{
"name": "spaces in a relative singular selector",
"selector" : "$[?length(@ .a .b) == 3]",
"document" : [ {"a": {"b": "foo"}}, {} ],
"result": [ {"a": {"b": "foo"}} ]
},
{
"name": "newlines in a relative singular selector",
"selector" : "$[?length(@\n.a\n.b) == 3]",
"document" : [ {"a": {"b": "foo"}}, {} ],
"result": [ {"a": {"b": "foo"}} ]
},
{
"name": "tabs in a relative singular selector",
"selector" : "$[?length(@\t.a\t.b) == 3]",
"document" : [ {"a": {"b": "foo"}}, {} ],
"result": [ {"a": {"b": "foo"}} ]
},
{
"name": "returns in a relative singular selector",
"selector" : "$[?length(@\r.a\r.b) == 3]",
"document" : [ {"a": {"b": "foo"}}, {} ],
"result": [ {"a": {"b": "foo"}} ]
},
{
"name": "spaces in an absolute singular selector ",
"selector" : "$..[?length(@)==length($ [0] .a)]",
"document" : [ {"a": "foo"}, {} ],
"result": [ "foo" ]
},
{
"name": "newlines in an absolute singular selector ",
"selector" : "$..[?length(@)==length($\n[0]\n.a)]",
"document" : [ {"a": "foo"}, {} ],
"result": [ "foo" ]
},
{
"name": "tabs in an absolute singular selector ",
"selector" : "$..[?length(@)==length($\t[0]\t.a)]",
"document" : [ {"a": "foo"}, {} ],
"result": [ "foo" ]
},
{
"name": "returns in an absolute singular selector ",
"selector" : "$..[?length(@)==length($\r[0]\r.a)]",
"document" : [ {"a": "foo"}, {} ],
"result": [ "foo" ]
}
]
}
14 changes: 7 additions & 7 deletions test/helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ void runTestsInDirectory(String dirName, {JsonPathParser? parser}) {
}

final document = t['document'];
final name = t['name'] as String?;
final paths = t['paths'] as List?;
final pointers = t['pointers'] as List?;
final selector = t['selector'] as String;
final skip = t['skip'] as String?;
final values = t['result'] as List?;
final invalid = t['invalid_selector'] as bool?;
final String? name = t['name'];
final List? paths = t['paths'];
final List? pointers = t['pointers'];
final String selector = t['selector'];
final String? skip = t['skip'];
final List? values = t['result'];
final bool? invalid = t['invalid_selector'];
group(name ?? selector, () {
if (values is List) {
test('values', () {
Expand Down

0 comments on commit ba70f05

Please sign in to comment.