`has()` and `in` treat a map entry whose value is `null` as absent

Aperta
#362 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à
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
bun, javascript, typescript
Ambito
backend, testing

Direzione di ricerca

Start by tracing how the map adapter handles key presence for has() and in; the issue points to that adapter as the likely fix. Run the listed examples with both plain objects and Map values, then add or update tests for null-valued entries. Done means both operators report the key as present while size() remains consistent.

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

Descrizione

Version: @bufbuild/cel 0.6.2 (run on Bun)

A map entry whose value is null is reported as absent by has() and in, but size() still counts it. The CEL spec defines has(m.f) on a map, and k in m, as tests of whether the key is present, whatever its value.

import { run } from "@bufbuild/cel";

run("has(m.a)", { m: { a: null } });                  // false, expected true
run('"a" in m', { m: { a: null } });                  // false, expected true
run("has(m.a)", { m: new Map([["a", null]]) });       // false, expected true
run('"a" in {"a": null}', {});                        // false, expected true
run('has({"a": null}.a)', {});                        // false, expected true
run('size({"a": null})', {});                         // 1n, so the entry exists

This matters when JSON data uses null to mean "present but empty": has() can't tell that apart from a missing field.

We work around it by wrapping maps before binding. The fix is probably to test key presence in the map adapter, rather than whether the value is null or undefined.

Lingua principale
TypeScript
Stelle
42
Fork
8
Merge medio
1g 12h
PR unite (30g)
5

Preparare l'ambiente

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 bufbuild/cel-es

Tutte le issue di bufbuild/cel-es

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.