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

Aperta Adatta ai principianti
#2,664 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript

Direzione di ricerca

Inizia da packages/core/src/util/path.ts, dove l’issue identifica le espressioni regolari in toDataPath come causa del percorso errato. Esamina i test esistenti per la conversione dei percorsi e aggiungi copertura per le proprietà chiamate then, else o something_else, insieme ai segmenti composti da parole chiave intere. Il lavoro è completato quando i segmenti delle proprietà vengono mantenuti mentre i segmenti delle parole chiave dello schema continuano a essere rimossi, così che il percorso segnalato diventi something_else.name.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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/

Lingua principale
TypeScript
Stelle
2.8k
Fork
423
Merge medio
5g 16h
PR unite (30g)
9

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di eclipsesource/jsonforms

Tutte le issue di eclipsesource/jsonforms

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.