Skip to content

Commit 90d5db2

Browse files
authored
fix: generate valid path segments for combinator paths with large indexes
The regex that converts a JSON Schema pointer to an instance path has been fixed. It now properly handles pointers with multi-digit indexes.
1 parent 9146b0f commit 90d5db2

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

packages/core/src/util/path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export { compose as composePaths };
5757
*/
5858
export const toDataPathSegments = (schemaPath: string): string[] => {
5959
const s = schemaPath
60-
.replace(/(anyOf|allOf|oneOf)\/[\d]\//g, '')
60+
.replace(/(anyOf|allOf|oneOf)\/[\d]+\//g, '')
6161
.replace(/(then|else)\//g, '');
6262
const segments = s.split('/');
6363

packages/core/test/util/path.test.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ test('toDataPath ', (t) => {
4444
t.is(toDataPath('#/properties/foo/properties/bar'), 'foo.bar');
4545
});
4646
test('toDataPath replace anyOf', (t) => {
47-
t.is(toDataPath('/anyOf/1/properties/foo/anyOf/1/properties/bar'), 'foo.bar');
47+
t.is(
48+
toDataPath('/anyOf/11/properties/foo/anyOf/11/properties/bar'),
49+
'foo.bar'
50+
);
4851
});
4952
test('toDataPath replace anyOf in combination with conditional schema compositions', (t) => {
5053
t.is(toDataPath('/anyOf/1/then/properties/foo'), 'foo');
@@ -59,7 +62,10 @@ test('toDataPath replace multiple nested properties with anyOf in combination wi
5962
);
6063
});
6164
test('toDataPath replace allOf', (t) => {
62-
t.is(toDataPath('/allOf/1/properties/foo/allOf/1/properties/bar'), 'foo.bar');
65+
t.is(
66+
toDataPath('/allOf/11/properties/foo/allOf/11/properties/bar'),
67+
'foo.bar'
68+
);
6369
});
6470
test('toDataPath replace allOf in combination with conditional schema compositions', (t) => {
6571
t.is(toDataPath('/allOf/1/then/properties/foo'), 'foo');
@@ -74,7 +80,10 @@ test('toDataPath replace multiple nested properties with allOf in combination wi
7480
);
7581
});
7682
test('toDataPath replace oneOf', (t) => {
77-
t.is(toDataPath('/oneOf/1/properties/foo/oneOf/1/properties/bar'), 'foo.bar');
83+
t.is(
84+
toDataPath('/oneOf/11/properties/foo/oneOf/11/properties/bar'),
85+
'foo.bar'
86+
);
7887
});
7988
test('toDataPath replace oneOf in combination with conditional schema compositions', (t) => {
8089
t.is(toDataPath('/oneOf/1/then/properties/foo'), 'foo');

0 commit comments

Comments
 (0)