Skip to content

Commit 4cfe887

Browse files
authored
v0.5.2 (#60)
1 parent a29af7f commit 4cfe887

21 files changed

+186
-28
lines changed

.github/workflows/publish.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@ on:
66
tags:
77
- '[0-9]+.[0-9]+.[0-9]+*'
88

9-
10-
# Publish using the reusable workflow from dart-lang.
119
jobs:
1210
publish:
13-
steps:
14-
- uses: actions/checkout@v2
15-
- name: Update submodules
16-
run: git config --global --add safe.directory '*' && git submodule update --init --recursive
17-
- uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
11+
needs: prepare
12+
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
13+
prepare:
14+
uses: ./test.yml
File renamed without changes.

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [0.5.2] - 2023-04-05
8+
### Added
9+
- Improved IRegex support
10+
711
## [0.5.1] - 2023-03-28
812
### Added
913
- Better support for Normalized Paths
@@ -137,6 +141,7 @@ Previously, no modification would be made and no errors/exceptions thrown.
137141
### Added
138142
- Basic design draft
139143

144+
[0.5.2]: https://github.com/f3ath/jessie/compare/0.5.1...0.5.2
140145
[0.5.1]: https://github.com/f3ath/jessie/compare/0.5.0...0.5.1
141146
[0.5.0]: https://github.com/f3ath/jessie/compare/0.4.4...0.5.0
142147
[0.4.4]: https://github.com/f3ath/jessie/compare/0.4.3...0.4.4

lib/src/fun/standard/string_matcher.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ abstract class StringMatcher implements Fun2<bool, Maybe, Maybe> {
2323
}
2424

2525
RegExp _makeRegex(String regex) =>
26-
RegExp(allowSubstring ? regex : '^$regex\$');
26+
RegExp(allowSubstring ? regex : '^$regex\$', unicode: true);
2727
}

lib/src/grammar/array_index_selector.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:json_path/src/selector/selector.dart';
1+
import 'package:json_path/src/selector.dart';
22

33
Selector arrayIndexSelector(int offset) => (node) sync* {
44
final element = node.element(offset);

lib/src/grammar/array_slice_selector.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:json_path/src/selector/selector.dart';
1+
import 'package:json_path/src/selector.dart';
22

33
Selector arraySliceSelector({int? start, int? stop, int? step}) =>
44
(node) sync* {

lib/src/grammar/child_selector.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:json_path/src/selector/selector.dart';
1+
import 'package:json_path/src/selector.dart';
22

33
Selector childSelector(String key) => (node) sync* {
44
final child = node.child(key);

lib/src/grammar/filter_selector.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:json_path/src/expression/expression.dart';
2-
import 'package:json_path/src/selector/selector.dart';
2+
import 'package:json_path/src/selector.dart';
33

44
Selector filterSelector(Expression<bool> filter) =>
55
(node) => node.children.where(filter.call);

lib/src/grammar/json_path.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'package:json_path/src/grammar/sequence_selector.dart';
1717
import 'package:json_path/src/grammar/strings.dart';
1818
import 'package:json_path/src/grammar/union_selector.dart';
1919
import 'package:json_path/src/grammar/wildcard.dart';
20-
import 'package:json_path/src/selector/selector.dart';
20+
import 'package:json_path/src/selector.dart';
2121
import 'package:maybe_just_nothing/maybe_just_nothing.dart';
2222
import 'package:petitparser/petitparser.dart';
2323

lib/src/grammar/sequence_selector.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:json_path/src/node.dart';
2-
import 'package:json_path/src/selector/selector.dart';
2+
import 'package:json_path/src/selector.dart';
33

44
Selector sequenceSelector(Iterable<Selector> selectors) {
55
final filter = selectors.fold<_Filter>((v) => v,

lib/src/grammar/strings.dart

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ final _escapedControl = _escapedSlash |
2626

2727
// The parser does not seem to support Unicode 6.0 boundary (0x10FFFF).
2828
// We're limiting ourselves to Unicode 1.0 boundary (0xFFFF).
29+
// TODO: work around by using surrogate pairs
2930
final _unicodeBoundary = String.fromCharCode(0xFFFF);
3031

3132
// Exclude double quote '"' and back slash '\'

lib/src/grammar/union_selector.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'package:json_path/src/selector/selector.dart';
1+
import 'package:json_path/src/selector.dart';
22

33
Selector unionSelector(Iterable<Selector> selectors) =>
44
(node) => selectors.expand((s) => s(node));

lib/src/json_path_internal.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:json_path/src/json_path.dart';
22
import 'package:json_path/src/json_path_match.dart';
33
import 'package:json_path/src/node.dart';
44
import 'package:json_path/src/node_match.dart';
5-
import 'package:json_path/src/selector/selector.dart';
5+
import 'package:json_path/src/selector.dart';
66

77
/// Internal implementation of [JsonPath].
88
class JsonPathInternal implements JsonPath {

lib/src/normalized/index_selector.dart

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/// Normalized index selector.
12
class IndexSelector {
23
IndexSelector(this.index);
34

lib/src/normalized/name_selector.dart

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1+
/// Normalized name selector.
12
class NameSelector {
23
NameSelector(this.name);
34

45
final String name;
56

67
@override
7-
String toString() => "['${_escape(name)}']";
8+
String toString() => "['${name.escaped}']";
9+
}
10+
11+
extension _StringExt on String {
12+
/// Returns a string with all characters escaped as unicode entities.
13+
String get unicodeEscaped =>
14+
codeUnits.map((c) => '\\u${c.toRadixString(16).padLeft(4, '0')}').join();
815

9-
String _escape(String string) => {
16+
String get escaped => const {
1017
r'/': r'\/',
1118
r'\': r'\\',
1219
'\b': r'\b',
@@ -17,9 +24,7 @@ class NameSelector {
1724
"'": r"\'",
1825
}
1926
.entries
20-
.fold(string, (s, e) => s.replaceAll(e.key, e.value))
27+
.fold(this, (s, e) => s.replaceAll(e.key, e.value))
2128
.replaceAllMapped(
22-
RegExp(r'[\u0000-\u001f]'),
23-
(s) =>
24-
'\\u${s[0]!.codeUnitAt(0).toRadixString(16).padLeft(4, '0')}');
29+
RegExp(r'[\u0000-\u001f]'), (s) => s[0]!.unicodeEscaped);
2530
}
File renamed without changes.

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_path
2-
version: 0.5.1
2+
version: 0.5.2
33
description: Implementation of JSONPath expressions like "$.store.book[2].price". Reads and writes values in parsed JSON objects.
44
homepage: "https://github.com/f3ath/jessie"
55

test/cases/cts

Submodule cts updated 1 file

test/cases/standard/escaping.json

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "escaping, single quotes, forward slash unescaped",
5+
"selector": "$['A/B']",
6+
"document": {"A/B": 42},
7+
"result": [42]
8+
}, {
9+
"name": "escaping, single quotes, forward slash escaped",
10+
"selector": "$['A\\/B']",
11+
"document": {"A/B": 42},
12+
"result": [42]
13+
}, {
14+
"name": "escaping, single quotes, \\b",
15+
"selector": "$['A\\bB']",
16+
"document": {"A\bB": 42},
17+
"result": [42]
18+
}, {
19+
"name": "escaping, single quotes, \\",
20+
"selector": "$['A\\\\B']",
21+
"document": {"A\\B": 42},
22+
"result": [42]
23+
}, {
24+
"name": "escaping, single quotes, \\t",
25+
"selector": "$['A\\tB']",
26+
"document": {"A\tB": 42},
27+
"result": [42]
28+
}, {
29+
"name": "escaping, single quotes, \\r",
30+
"selector": "$['A\\rB']",
31+
"document": {"A\rB": 42},
32+
"result": [42]
33+
}, {
34+
"name": "escaping, single quotes, \\n",
35+
"selector": "$['A\\nB']",
36+
"document": {"A\nB": 42},
37+
"result": [42]
38+
}, {
39+
"name": "escaping, single quotes, \\f",
40+
"selector": "$['A\\fB']",
41+
"document": {"A\fB": 42},
42+
"result": [42]
43+
}, {
44+
"name": "escaping, single quotes, \"",
45+
"selector": "$['A\"B']",
46+
"document": {"A\"B": 42},
47+
"result": [42]
48+
}, {
49+
"name": "escaping, single quotes, '",
50+
"selector": "$['A\\'B']",
51+
"document": {"A'B": 42},
52+
"result": [42]
53+
}, {
54+
"name": "escaping, double quotes, forward slash unescaped",
55+
"selector": "$[\"A/B\"]",
56+
"document": {"A/B": 42},
57+
"result": [42]
58+
}, {
59+
"name": "escaping, double quotes, forward slash escaped",
60+
"selector": "$[\"A\\/B\"]",
61+
"document": {"A/B": 42},
62+
"result": [42]
63+
}, {
64+
"name": "escaping, double quotes, \\b",
65+
"selector": "$[\"A\\bB\"]",
66+
"document": {"A\bB": 42},
67+
"result": [42]
68+
}, {
69+
"name": "escaping, double quotes, \\",
70+
"selector": "$[\"A\\\\B\"]",
71+
"document": {"A\\B": 42},
72+
"result": [42]
73+
}, {
74+
"name": "escaping, double quotes, \\t",
75+
"selector": "$[\"A\\tB\"]",
76+
"document": {"A\tB": 42},
77+
"result": [42]
78+
}, {
79+
"name": "escaping, double quotes, \\r",
80+
"selector": "$[\"A\\rB\"]",
81+
"document": {"A\rB": 42},
82+
"result": [42]
83+
}, {
84+
"name": "escaping, double quotes, \\n",
85+
"selector": "$[\"A\\nB\"]",
86+
"document": {"A\nB": 42},
87+
"result": [42]
88+
}, {
89+
"name": "escaping, double quotes, \\f",
90+
"selector": "$[\"A\\fB\"]",
91+
"document": {"A\fB": 42},
92+
"result": [42]
93+
}, {
94+
"name": "escaping, double quotes, \"",
95+
"selector": "$[\"A\\\"B\"]",
96+
"document": {"A\"B": 42},
97+
"result": [42]
98+
}, {
99+
"name": "escaping, double quotes, '",
100+
"selector": "$[\"A'B\"]",
101+
"document": {"A'B": 42},
102+
"result": [42]
103+
}
104+
]
105+
}

test/cases/standard/fun_match.json

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "filter, match function, unicode char class, uppercase",
5+
"selector": "$[?match(@, '\\\\p{Lu}')]",
6+
"document": ["ж", "Ж", "1", "жЖ", true, [], {}],
7+
"result": ["Ж"]
8+
},
9+
{
10+
"name": "filter, match function, unicode char class negated, uppercase",
11+
"selector": "$[?match(@, '\\\\P{Lu}')]",
12+
"document": ["ж", "Ж", "1", true, [], {}],
13+
"result": ["ж", "1"]
14+
},
15+
{
16+
"name": "filter, match function, unicode, surrogate pair",
17+
"selector": "$[?match(@, 'a.b')]",
18+
"document": ["a\uD800\uDD01b", "ab", "1", true, [], {}],
19+
"result": ["a\uD800\uDD01b"]
20+
}
21+
]
22+
}

test/cases/standard/fun_search.json

+26-4
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,41 @@
44
"selector": "$[?search(@, 'a')]",
55
"document": ["abc", "bcd", "bab", "bba", "a", true, [], {}],
66
"result": ["abc", "bab", "bba", "a"]
7-
}, {
7+
},
8+
{
9+
"name": "filter, search function, unicode char class, uppercase",
10+
"selector": "$[?search(@, '\\\\p{Lu}')]",
11+
"document": ["ж", "Ж", "1", "жЖ", true, [], {}],
12+
"result": ["Ж", "жЖ"]
13+
},
14+
{
15+
"name": "filter, search function, unicode char class negated, uppercase",
16+
"selector": "$[?search(@, '\\\\P{Lu}')]",
17+
"document": ["ж", "Ж", "1", true, [], {}],
18+
"result": ["ж", "1"]
19+
},
20+
{
21+
"name": "filter, search function, unicode, surrogate pair",
22+
"selector": "$[?search(@, 'a.b')]",
23+
"document": ["a\uD800\uDD01bc", "abc", "1", true, [], {}],
24+
"result": ["a\uD800\uDD01bc"]
25+
},
26+
{
827
"selector": "$.foo[?search(@, 'a')]",
928
"document": {"foo": ["abc", "bcd", "bab", "bba", "a", true, [], {}]},
1029
"result": ["abc", "bab", "bba", "a"]
11-
}, {
30+
},
31+
{
1232
"selector": "$[?search('bab', 'a')]",
1333
"document": ["abc", "bcd", "bab", "bba", "a", true, [], {}],
1434
"result": ["abc", "bcd", "bab", "bba", "a", true, [], {}]
15-
}, {
35+
},
36+
{
1637
"selector": "$.result[?search(@, $.regex)]",
1738
"document": {"regex": "b.?b", "result": ["abc", "bcd", "bab", "bba", "a", true, [], {}]},
1839
"result": ["bab", "bba"]
19-
}, {
40+
},
41+
{
2042
"selector": "$.result[?search(@, $.regex)]",
2143
"document": {"regex": "invalid][$^", "result": ["abc", "bcd", "bab", "bba", "a", true, [], {}]},
2244
"result": []

0 commit comments

Comments
 (0)