Repository navigation
Conversation
The anyOf/allOf/oneOf and then/else regexes matched inside property names (something_else, strengthen) and also removed properties literally named then or else. Walk the pointer segment by segment instead and only skip keywords where a keyword is expected. Fixes eclipsesource#2664
✅ Deploy Preview for jsonforms-examples ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
lucas-koehler
left a comment
There was a problem hiding this comment.
Hi @trackoor , thank you for the contribution ❤️
The PR already looks pretty good to me. I have two comments inline (one of them being optional). Please have a look.
| while (i < segments.length) { | ||
| const segment = segments[i]; | ||
| if ( | ||
| (segment === 'anyOf' || segment === 'allOf' || segment === 'oneOf') && |
There was a problem hiding this comment.
This changes the output for a scope that ends in a combinator index. #/properties/a/anyOf/0 used to give a.0 and now gives a, which is the right data path since anyOf/N doesn't add a data level. The old result only came from the regex requiring a trailing slash. The PR description says the output for all existing paths is unchanged, so please mention this and add a test for it.
| return range(startIndex, decodedSegments.length, 2).map( | ||
| (idx) => decodedSegments[idx] | ||
| ); | ||
| const segments = schemaPath.split('/').map(decode); |
There was a problem hiding this comment.
One thing came up reviewing this PR regarding decode (path.ts:107). It uses .replace(/~0/, '~') without the g flag, so only the first ~0 in a segment is decoded. Adding the flag would fix it, ideally together with a test like a~0b~0c giving a~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 😊
Fixes #2664.
toDataPathSegmentsremovedanyOf/N/,allOf/N/,oneOf/N/andthen//else/with regexes over the whole scope string, so they also matched inside property names (something_elsebecamesomething_properties) and removed properties that are literally namedthenorelse.It now splits the scope into segments first and walks them: a combinator keyword followed by an index and a
then/elsesegment are skipped where a keyword is expected, and the segment afterpropertiesis always taken as the property name. The output for all existing paths is unchanged.I added two tests to
packages/core/test/util/path.test.ts(property names ending inthen/else, and properties namedthen,elseandanyOf). Both fail on master and pass with the change. The full core suite (447 tests) andeslint .inpackages/corepass.I used an AI coding assistant to help write this; I reviewed the change and ran the tests.