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

Ouverte Adaptée aux débutants
#2,664 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
react, typescript

Piste de recherche

Commencez par packages/core/src/util/path.ts, où l’issue identifie les expressions régulières de toDataPath comme la source du chemin incorrect. Examinez les tests existants de conversion de chemins et ajoutez une couverture pour les propriétés nommées then, else ou something_else, ainsi que pour les segments constitués de mots-clés entiers. Le travail est terminé lorsque les segments de propriété sont conservés tandis que les segments de mots-clés du schéma sont toujours supprimés, de sorte que le chemin signalé devienne something_else.name.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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/

Langage dominant
TypeScript
Étoiles
2.8k
Forks
423
Merge moyen
5 j 16 h
PR mergées (30 j)
9

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de eclipsesource/jsonforms

Toutes les issues de eclipsesource/jsonforms

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.