Skip to content

fix(core): only drop whole keyword segments in toDataPathSegments - #2675

Open
trackoor wants to merge 1 commit into
eclipsesource:masterfrom
trackoor:fix/to-data-path-keyword-segments
Open

trackoor wants to merge 1 commit into
eclipsesource:masterfrom
trackoor:fix/to-data-path-keyword-segments

Conversation

@trackoor

Copy link
Copy Markdown

Fixes #2664.

toDataPathSegments removed anyOf/N/, allOf/N/, oneOf/N/ and then//else/ with regexes over the whole scope string, so they also matched inside property names (something_else became something_properties) and removed properties that are literally named then or else.

It now splits the scope into segments first and walks them: a combinator keyword followed by an index and a then/else segment are skipped where a keyword is expected, and the segment after properties is 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 in then/else, and properties named then, else and anyOf). Both fail on master and pass with the change. The full core suite (447 tests) and eslint . in packages/core pass.

I used an AI coding assistant to help write this; I reviewed the change and ran the tests.

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
@CLAassistant

CLAassistant commented Nov 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@netlify

netlify Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for jsonforms-examples ready!

Name Link
🔨 Latest commit 45612c8
🔍 Latest deploy log https://app.netlify.com/projects/jsonforms-examples/deploys/6b00ffed30ae92e7fd07db9c
😎 Deploy Preview https://deploy-preview-2675--jsonforms-examples.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 84.905% — trackoor:fix/to-data-path-keyword-segments into eclipsesource:master. No base build found for eclipsesource:master.

@lucas-koehler lucas-koehler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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') &&

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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. #/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);

Copy link
Copy Markdown
Contributor

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 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 😊

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scope through a property whose name ends in "then" or "else" binds the control to the wrong data path

4 participants