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

Đang mở Phù hợp với người mới
#2,664 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
react, typescript

Hướng nghiên cứu

Bắt đầu với packages/core/src/util/path.ts, nơi issue xác định các biểu thức chính quy trong toDataPath là nguyên nhân gây ra đường dẫn không chính xác. Kiểm tra các bài kiểm thử hiện có về chuyển đổi đường dẫn và bổ sung kiểm thử cho các thuộc tính có tên then, else hoặc something_else, cùng với các phân đoạn là từ khóa hoàn chỉnh. Công việc được xem là hoàn tất khi các phân đoạn thuộc tính được giữ nguyên, còn các phân đoạn từ khóa của schema vẫn bị loại bỏ, để đường dẫn được báo cáo trở thành something_else.name.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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/

Ngôn ngữ chính
TypeScript
Star
2.8k
Fork
423
Merge trung bình
5 ngày 16 giờ
Pull request đã merge (30 ngày)
9

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của eclipsesource/jsonforms

Tất cả issue của eclipsesource/jsonforms

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.