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

オープン 初心者向け
#2,664 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
react, typescript

調査の方向性

issueで誤ったパスの原因としてtoDataPath内の正規表現が指摘されているため、まずpackages/core/src/util/path.tsを確認します。パス変換の既存テストを調べ、then、else、something_elseという名前のプロパティと、キーワード全体からなるセグメントのテストを追加します。プロパティのセグメントが保持され、スキーマのキーワードセグメントは引き続き削除され、報告されたパスが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時間
マージ済み PR(30日)
9

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

eclipsesource/jsonforms のほかの issue

eclipsesource/jsonforms の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。