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

未关闭 适合新手
#2,664 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
react, typescript

调研方向

从 packages/core/src/util/path.ts 开始;issue 指出其中 toDataPath 的正则表达式是路径错误的原因。检查现有的路径转换测试,并补充对名为 then、else 或 something_else 的属性,以及完整关键字片段的测试。完成标准是保留属性片段,同时仍然移除 schema 关键字片段,使报告的路径变为 something_else.name。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

toDataPathSegments strips then/ and else/ (and anyOf/N/ etc.) anywhere in the scope string, not only as whole path segments. So a scope that goes through a property named then, else, something_else, strengthen, ... is turned into a wrong data path:

import { toDataPath } from "@jsonforms/core";
toDataPath("#/properties/something_else/properties/name"); // "something_properties"
toDataPath("#/properties/then/properties/name");           // "properties"
toDataPath("#/properties/strengthen/properties/x");        // "strengproperties"

In a form the control shows nothing and typing writes to a new top-level key. With the React vanilla renderers, data { something_else: { name: "Bob" } } shows an empty input, and typing "Alice" produces

{"something_else":{"name":"Bob"},"something_properties":"Alice"}

Rules whose condition scope goes through such a property read the wrong value too.

Expected behavior

toDataPath("#/properties/something_else/properties/name") is "something_else.name", the input shows "Bob", and typing gives {"something_else":{"name":"Alice"}}. Only whole then/else segments (as in #/then/properties/x) should be dropped.

Steps to reproduce the issue
import { JsonForms } from "@jsonforms/react";
import { vanillaRenderers, vanillaCells } from "@jsonforms/vanilla-renderers";

const schema = {
  type: "object",
  properties: {
    something_else: { type: "object", properties: { name: { type: "string" } } },
  },
};
const uischema = {
  type: "VerticalLayout",
  elements: [{ type: "Control", scope: "#/properties/something_else/properties/name" }],
};

<JsonForms
  schema={schema}
  uischema={uischema}
  data={{ something_else: { name: "Bob" } }}
  renderers={vanillaRenderers}
  cells={vanillaCells}
  onChange={({ data }) => console.log(JSON.stringify(data))}
/>;
  1. Render the form: the input is empty instead of "Bob".
  2. Type "Alice": onChange logs {"something_else":{"name":"Bob"},"something_properties":"Alice"}.

With a property named name2 instead, the same form works.

Screenshots

No response

Which Version of JSON Forms are you using?

v3.8.0 (also master 942b76f)

Package

Core

Additional context

The regexes in packages/core/src/util/path.ts are /(anyOf|allOf|oneOf)\/[\d]+\//g and /(then|else)\//g. They match inside a segment, and they also match a segment that is a property name, so the scope would need to be split into segments first and then/else/anyOf/N dropped only where a keyword is expected (not right after properties).

Credit: https://ucsbplse.github.io/

主要语言
TypeScript
星标
2.8k
派生
423
平均合并
5 天 16 小时
30 天内合并 PR
9

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

eclipsesource/jsonforms 的其他 Issue

查看 eclipsesource/jsonforms 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。