Repository navigation
fix(core): only drop whole keyword segments in toDataPathSegments #2675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,6 @@ | |
| */ | ||
|
|
||
| import isEmpty from 'lodash/isEmpty'; | ||
| import range from 'lodash/range'; | ||
|
|
||
| export const compose = (path1: string, path2: string) => { | ||
| let p1 = path1; | ||
|
|
@@ -55,18 +54,29 @@ export { compose as composePaths }; | |
| * @returns {string[]} an array containing only non-schema-specific segments | ||
| */ | ||
| export const toDataPathSegments = (schemaPath: string): string[] => { | ||
| const s = schemaPath | ||
| .replace(/(anyOf|allOf|oneOf)\/[\d]+\//g, '') | ||
| .replace(/(then|else)\//g, ''); | ||
| const segments = s.split('/'); | ||
|
|
||
| const decodedSegments = segments.map(decode); | ||
|
|
||
| const startFromRoot = decodedSegments[0] === '#' || decodedSegments[0] === ''; | ||
| const startIndex = startFromRoot ? 2 : 1; | ||
| return range(startIndex, decodedSegments.length, 2).map( | ||
| (idx) => decodedSegments[idx] | ||
| ); | ||
| const segments = schemaPath.split('/').map(decode); | ||
| const startFromRoot = segments[0] === '#' || segments[0] === ''; | ||
| const dataSegments: string[] = []; | ||
| // Walk the pointer segment by segment so that keywords are only skipped | ||
| // where a keyword is expected, never inside or in place of a property name | ||
| let i = startFromRoot ? 1 : 0; | ||
| while (i < segments.length) { | ||
| const segment = segments[i]; | ||
| if ( | ||
| (segment === 'anyOf' || segment === 'allOf' || segment === 'oneOf') && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This changes the output for a scope that ends in a combinator index. |
||
| /^\d+$/.test(segments[i + 1] ?? '') | ||
| ) { | ||
| i += 2; | ||
| } else if (segment === 'then' || segment === 'else') { | ||
| i += 1; | ||
| } else { | ||
| if (i + 1 < segments.length) { | ||
| dataSegments.push(segments[i + 1]); | ||
| } | ||
| i += 2; | ||
| } | ||
| } | ||
| return dataSegments; | ||
| }; | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing came up reviewing this PR regarding
decode(path.ts:107). It uses.replace(/~0/, '~')without thegflag, so only the first~0in a segment is decoded. Adding the flag would fix it, ideally together with a test likea~0b~0cgivinga~b~c.If you want to fix that as part of this PR that would be appreciated but not expected as this is a pre-existing bug. Do however you see fit 😊