[BUG] Targeting can't select variants whose names contain `&`, `<`, `>`, `\` or `"`

Aperta
#2,120 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@RaphaelFakhri ci sta già lavorando.

Dal 5/11/2026.

  • #2121 di @RaphaelFakhri — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
api, backend

Direzione di ricerca

Start in core/pkg/evaluator/json.go at evaluateVariant, where the issue identifies JSON encoding and manual quote removal as the cause. Reproduce the case with a variant name containing escaped characters and compare the resolved variant with the expected TARGETING_MATCH result. The issue links an open pull request for this fix.

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

Descrizione

Observed behavior

When a targeting rule returns the name of a variant that contains &, <, >, \ or ", the evaluation fails with GENERAL and flagd logs invalid or missing variant. The variant exists in the flag definition, and the same variant works as defaultVariant.

The cause is in evaluateVariant (core/pkg/evaluator/json.go). The JsonLogic result is written with json.NewEncoder, which escapes HTML characters by default (& becomes \u0026, < becomes \u003c). It also escapes \ and ". flagd then removes the quotes from the encoded string by hand and doesn't decode the escapes. As a result, "R&D" is looked up as R\u0026D.

Expected behavior

A targeting rule that returns a valid variant name resolves to that variant with reason TARGETING_MATCH, whatever characters the name contains.

Steps to reproduce
  1. Save this as flags.json:

    {
      "flags": {
        "team": {
          "state": "ENABLED",
          "variants": { "off": "off", "R&D": "rd" },
          "defaultVariant": "off",
          "targeting": { "if": [{ "==": [{ "var": "dept" }, "rd"] }, "R&D", "off"] }
        }
      }
    }
    
  2. Start flagd: flagd start -f file:flags.json.

  3. Evaluate the flag:

    curl -X POST -H "Content-Type: application/json" \
      -d '{"flagKey":"team","context":{"dept":"rd"}}' \
      http://localhost:8013/flagd.evaluation.v1.Service/ResolveString
    
  4. The response is a GENERAL error instead of {"value":"rd","variant":"R&D","reason":"TARGETING_MATCH"}.

Lingua principale
Go
Stelle
1k
Fork
151
Merge medio
5g 5h
PR unite (30g)
14

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 open-feature/flagd

Tutte le issue di open-feature/flagd

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.