Skip to content

Commit b5ee5fc

Browse files
Update to Spec 3.0.3 (#100)
* Update the comformance test suite for 3.0.3 * Fix the regex for keyed array pattern * Update spec version number from 3.0.1 to 3.0.3 * update pmd because warnings on build * for better reading adding linebreak. * pmd warning fixed. * remove unused local var. --------- Co-authored-by: Felipe Stanzani <stanzani@gmail.com>
1 parent b09a8ed commit b5ee5fc

File tree

8 files changed

+87
-7
lines changed

8 files changed

+87
-7
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Release](https://github.com/toon-format/toon-java/actions/workflows/release.yml/badge.svg)](https://github.com/toon-format/toon-java/actions/workflows/release.yml)
55
[![Maven Central](https://img.shields.io/maven-central/v/dev.toonformat/jtoon.svg)](https://central.sonatype.com/artifact/dev.toonformat/jtoon)
66
![Coverage](.github/badges/jacoco.svg)
7-
[![SPEC v3.0.1](https://img.shields.io/badge/spec-v3.0.1-fef3c0?labelColor=1b1b1f)](https://github.com/toon-format/spec)
7+
[![SPEC v3.0.3](https://img.shields.io/badge/spec-v3.0.3-fef3c0?labelColor=1b1b1f)](https://github.com/toon-format/spec)
88
[![License: MIT](https://img.shields.io/badge/license-MIT-fef3c0?labelColor=1b1b1f)](./LICENSE)
99

1010
> **⚠️ Beta Status (v1.x.x):** This library is in active development and working towards spec compliance. Beta published to Maven Central. API may change before 2.0.0 release.

src/main/java/dev/toonformat/jtoon/encoder/ObjectEncoder.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,11 @@ public static void encodeKeyValuePair(final String key,
104104
final int remainingDepth = effectiveFlattenDepth - depth;
105105
EncodeOptions currentOptions = options;
106106

107-
// Attempt key folding when enabled
108-
final KeyFolding flattenMode = currentOptions.flatten();
109107
if (remainingDepth > 0
110108
&& !siblings.isEmpty()
111109
&& blockedKeys != null
112110
&& !blockedKeys.contains(key)
113-
&& flattenMode != null
114-
&& flattenMode == KeyFolding.SAFE) {
111+
&& KeyFolding.SAFE == currentOptions.flatten()) {
115112
final Flatten.FoldResult foldResult = Flatten.tryFoldKeyChain(key, value, siblings, rootLiteralKeys,
116113
pathPrefix, remainingDepth);
117114
if (foldResult != null) {

src/main/java/dev/toonformat/jtoon/util/Headers.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ public final class Headers {
2222

2323
/**
2424
* Matches keyed array headers: items[2]{id,name}: or tags[3]: or data[4]{id}:.
25-
* Captures: group(1)=key, group(2)=#marker, group(3)=delimiter,
25+
* Also matches quoted keys with brackets: "key[test]"[3]:.
26+
* Captures: group(1)=key (quoted or unquoted), group(2)=#marker, group(3)=delimiter,
2627
* group(4)=optional field spec
2728
*/
28-
public static final Pattern KEYED_ARRAY_PATTERN = Pattern.compile("^(.+?)\\[(#?)\\d+([\\t|])?](\\{[^}]+})?:.*$");
29+
public static final Pattern KEYED_ARRAY_PATTERN = Pattern.compile(
30+
"^(\"[^\"]+\"|[^\\[\\]]+)\\[(#?)\\d+([\\t|])?](\\{[^}]+})?:.*$");
2931

3032
private Headers() {
3133
throw new UnsupportedOperationException("Utility class cannot be instantiated");

src/test/resources/conformance/decode/arrays-primitive.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@
9191
},
9292
"specSection": "9.1"
9393
},
94+
{
95+
"name": "parses quoted empty string key with inline array",
96+
"input": "\"\"[3]: 1,2,3",
97+
"expected": {
98+
"": [1, 2, 3]
99+
},
100+
"specSection": "9.1"
101+
},
94102
{
95103
"name": "parses quoted key containing brackets with inline array",
96104
"input": "\"key[test]\"[3]: 1,2,3",
@@ -106,6 +114,14 @@
106114
"x-custom": []
107115
},
108116
"specSection": "9.1"
117+
},
118+
{
119+
"name": "parses quoted empty string key with empty array",
120+
"input": "\"\"[0]:",
121+
"expected": {
122+
"": []
123+
},
124+
"specSection": "9.1"
109125
}
110126
]
111127
}

src/test/resources/conformance/decode/arrays-tabular.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@
5858
},
5959
"specSection": "9.3"
6060
},
61+
{
62+
"name": "parses quoted empty string key with tabular array format",
63+
"input": "\"\"[2]{id,name}:\n 1,Ada\n 2,Bob",
64+
"expected": {
65+
"": [
66+
{ "id": 1, "name": "Ada" },
67+
{ "id": 2, "name": "Bob" }
68+
]
69+
},
70+
"specSection": "9.3"
71+
},
6172
{
6273
"name": "treats unquoted colon as terminator for tabular rows and start of key-value pair",
6374
"input": "items[2]{id,name}:\n 1,Alice\n 2,Bob\ncount: 2",

src/test/resources/conformance/decode/objects.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,33 @@
118118
},
119119
"specSection": "8"
120120
},
121+
{
122+
"name": "treats extra brackets after valid array segment as literal key",
123+
"input": "foo[1][bar]: 10",
124+
"expected": {
125+
"foo[1][bar]": 10
126+
},
127+
"specSection": "6",
128+
"note": "Non-whitespace [bar] between ] and : prevents array header interpretation"
129+
},
130+
{
131+
"name": "treats non-integer bracket content as literal key",
132+
"input": "foo[bar][1]: 20",
133+
"expected": {
134+
"foo[bar][1]": 20
135+
},
136+
"specSection": "6",
137+
"note": "[bar] fails integer parsing; line is not an array header"
138+
},
139+
{
140+
"name": "treats text between bracket segment and colon as literal key",
141+
"input": "foo[2]extra: a,b",
142+
"expected": {
143+
"foo[2]extra": "a,b"
144+
},
145+
"specSection": "6",
146+
"note": "Non-whitespace content between ] and : prevents array header interpretation"
147+
},
121148
{
122149
"name": "parses quoted key with braces",
123150
"input": "\"{key}\": 5",

src/test/resources/conformance/encode/arrays-primitive.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,22 @@
3535
"expected": "items[0]:",
3636
"specSection": "9.1"
3737
},
38+
{
39+
"name": "encodes empty string keys for inline arrays",
40+
"input": {
41+
"": [1, 2, 3]
42+
},
43+
"expected": "\"\"[3]: 1,2,3",
44+
"specSection": "9.1"
45+
},
46+
{
47+
"name": "encodes empty string keys for empty arrays",
48+
"input": {
49+
"": []
50+
},
51+
"expected": "\"\"[0]:",
52+
"specSection": "9.1"
53+
},
3854
{
3955
"name": "encodes empty string in single-item array",
4056
"input": {

src/test/resources/conformance/encode/arrays-tabular.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@
5757
},
5858
"expected": "items[2]{\"order:id\",\"full name\"}:\n 1,Ada\n 2,Bob",
5959
"specSection": "9.3"
60+
},
61+
{
62+
"name": "encodes tabular arrays with empty string keys",
63+
"input": {
64+
"": [
65+
{ "id": 1, "name": "Ada" },
66+
{ "id": 2, "name": "Bob" }
67+
]
68+
},
69+
"expected": "\"\"[2]{id,name}:\n 1,Ada\n 2,Bob",
70+
"specSection": "9.3"
6071
}
6172
]
6273
}

0 commit comments

Comments
 (0)