Skip to content

Commit 18f7398

Browse files
authored
V0.5.1 (#54)
1 parent f56df63 commit 18f7398

12 files changed

+117
-20
lines changed

.gitmodules

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
[submodule "cts"]
2-
path = cts
1+
2+
[submodule "test/cases/cts"]
3+
path = test/cases/cts
34
url = https://github.com/jsonpath-standard/jsonpath-compliance-test-suite.git

.pubignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
cts
1+
test/cases/cts
22
.coverage
33

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.1] - 2023-03-28
8+
### Added
9+
- Better support for Normalized Paths
10+
711
## [0.5.0] - 2023-03-23
812
### Added
913
- Full support of some built-in functions: `length()`, `size()`, `search()`, `match()`, `value()`.
@@ -133,6 +137,7 @@ Previously, no modification would be made and no errors/exceptions thrown.
133137
### Added
134138
- Basic design draft
135139

140+
[0.5.1]: https://github.com/f3ath/jessie/compare/0.5.0...0.5.1
136141
[0.5.0]: https://github.com/f3ath/jessie/compare/0.4.4...0.5.0
137142
[0.4.4]: https://github.com/f3ath/jessie/compare/0.4.3...0.4.4
138143
[0.4.3]: https://github.com/f3ath/jessie/compare/0.4.2...0.4.3

cts

-1
This file was deleted.

lib/src/node_match.dart

+4-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import 'package:json_path/json_path.dart';
22
import 'package:json_path/src/node.dart';
3+
import 'package:json_path/src/normalized/index_selector.dart';
4+
import 'package:json_path/src/normalized/name_selector.dart';
35
import 'package:rfc_6901/rfc_6901.dart';
46

57
class NodeMatch implements JsonPathMatch {
@@ -35,16 +37,5 @@ extension _NodeExt<T> on Node<T> {
3537
String path() => r'$' + trace().map(_segment).join();
3638
}
3739

38-
String _segment(Object? e) =>
39-
e is int ? '[$e]' : "['${_escape(e.toString())}']";
40-
41-
String _escape(String string) => {
42-
r'/': r'\/',
43-
r'\': r'\\',
44-
'\b': r'\b',
45-
'\f': r'\f',
46-
'\n': r'\n',
47-
'\r': r'\r',
48-
'\t': r'\t',
49-
"'": r"\'",
50-
}.entries.fold(string, (s, e) => s.replaceAll(e.key, e.value));
40+
Object _segment(Object? e) =>
41+
e is int ? IndexSelector(e) : NameSelector(e.toString());
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class IndexSelector {
2+
IndexSelector(this.index);
3+
4+
final int index;
5+
6+
@override
7+
String toString() => '[$index]';
8+
}

lib/src/normalized/name_selector.dart

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class NameSelector {
2+
NameSelector(this.name);
3+
4+
final String name;
5+
6+
@override
7+
String toString() => "['${_escape(name)}']";
8+
9+
String _escape(String string) => {
10+
r'/': r'\/',
11+
r'\': r'\\',
12+
'\b': r'\b',
13+
'\f': r'\f',
14+
'\n': r'\n',
15+
'\r': r'\r',
16+
'\t': r'\t',
17+
"'": r"\'",
18+
}
19+
.entries
20+
.fold(string, (s, e) => s.replaceAll(e.key, e.value))
21+
.replaceAllMapped(
22+
RegExp(r'[\u0000-\u001f]'),
23+
(s) =>
24+
'\\u${s[0]!.codeUnitAt(0).toRadixString(16).padLeft(4, '0')}');
25+
}

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: json_path
2-
version: 0.5.0
2+
version: 0.5.1
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 added at 71bf641
+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"tests": [
3+
{
4+
"name": "escaped characters",
5+
"selector": "$[*]",
6+
"document": {
7+
"\u0000": "NUL",
8+
"\u0001": "SOH",
9+
"\u0002": "STX",
10+
"\u0003": "ETX",
11+
"\u0004": "EOT",
12+
"\u0005": "ENQ",
13+
"\u0006": "ACK",
14+
"\u0007": "nul",
15+
"\u0008": "BS, backspace",
16+
"\u0009": "HT, tab",
17+
"\u000A": "LF, new line",
18+
"\u000B": "VT",
19+
"\u000C": "FF, form feed",
20+
"\u000D": "CR, carriage return",
21+
"\u000E": "SO",
22+
"\u000F": "SI",
23+
"\u001F": "US",
24+
"'": "single quote/apostrophe",
25+
"\\": "backslash"
26+
},
27+
"paths": [
28+
"$['\\u0000']",
29+
"$['\\u0001']",
30+
"$['\\u0002']",
31+
"$['\\u0003']",
32+
"$['\\u0004']",
33+
"$['\\u0005']",
34+
"$['\\u0006']",
35+
"$['\\u0007']",
36+
"$['\\b']",
37+
"$['\\t']",
38+
"$['\\n']",
39+
"$['\\u000b']",
40+
"$['\\f']",
41+
"$['\\r']",
42+
"$['\\u000e']",
43+
"$['\\u000f']",
44+
"$['\\u001f']",
45+
"$['\\'']",
46+
"$['\\\\']"
47+
]
48+
},
49+
{
50+
"name": "unescaped characters",
51+
"selector": "$[*]",
52+
"document": {
53+
"\"": "double quote",
54+
"[]": "[]",
55+
"\ud83d\ude00": "smiley face",
56+
"\u10FFFF": "0x10FFFF"
57+
},
58+
"paths": [
59+
"$['\"']",
60+
"$['[]']",
61+
"$['\uD83D\uDE00']",
62+
"$['\u10FFFF']"
63+
]
64+
}
65+
]
66+
}

test/cases_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:json_path/json_path.dart';
44
import 'helper.dart';
55

66
void main() {
7-
runTestsInDirectory('cts');
7+
runTestsInDirectory('test/cases/cts');
88
runTestsInDirectory('test/cases/standard');
99
runTestsInDirectory('test/cases/extra',
1010
parser: JsonPathParser(functions: [

test/helper.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ void runTestsInDirectory(String dirName, {JsonPathParser? parser}) {
1414
Directory(dirName)
1515
.listSync()
1616
.whereType<File>()
17-
.where((file) => file.path.endsWith('.json'))
17+
.where((file) =>
18+
file.path.endsWith('.json') && !file.path.endsWith('.schema.json'))
1819
.forEach((file) {
1920
group(path.basename(file.path), () {
2021
final cases = jsonDecode(file.readAsStringSync());

0 commit comments

Comments
 (0)