[Bug]: json-xml-mediator policy writes large and small JSON numbers in exponent form

Aperta Adatta ai principianti
#4,465 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
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
api, backend

Direzione di ricerca

Inizia individuando il codice della policy json-xml-mediator che formatta i numeri JSON con il verbo %g di Go; l’issue identifica la policy e il comportamento interessato, ma non indica file o test. Verifica come i test esistenti della policy coprono la conversione da JSON a XML, quindi aggiungi casi per 1234567 e 0.00001. Il lavoro è concluso quando questi elementi XML mantengono i valori decimali invece di usare la notazione esponenziale e i test pertinenti hanno esito positivo.

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

Descrizione

Area/Policies Aspect/API Severity/Major Type/Bug
Please select the area the issue is related to

Gateway

Please select the aspect the issue is related to

Aspect/API (API backends, definitions, contracts, interfaces, OpenAPI)

Description

The json-xml-mediator policy converts a JSON request to XML for the backend. It formats every JSON number with Go's %g verb.

%g switches to exponent form for numbers of a million or more and for numbers below 0.0001. So 1234567 reaches the backend as 1.234567e+06, and 0.00001 as 1e-05. An XML backend that expects decimal digits rejects or misreads these values.

Numbers between 0.0001 and a million are not affected. The policy doc says the policy converts all JSON data types.

Expected Behaviour

The XML element holds the number as the JSON wrote it, such as 1234567 and 0.00001.

Actual Behaviour

The backend receives <root><population>1.234567e+06</population><ratio>1e-05</ratio></root>.

Steps to Reproduce
  1. Create a REST API with the policy on a POST operation:
    {"name":"json-xml-mediator","version":"v1","params":{"downsteamPayloadFormat":"json","upstreamPayloadFormat":"xml"}}
    
  2. Send {"population":12345,"ratio":0.5} with Content-Type: application/json. The backend receives <root><population>12345</population><ratio>0.5</ratio></root>.
  3. Send {"population":1234567,"ratio":0.00001}. The backend receives <root><population>1.234567e+06</population><ratio>1e-05</ratio></root>.
Severity Level of the Issue

Severity/Major (Important functionality is broken. Should be prioritized. Doesn't need immediate attention)

Environment Details (with versions)
  • Gateway versions: 1.1.0, 1.2.0 and latest
  • Policy: json-xml-mediator v1.1.0, wso2/gateway-controllers main 5b8e3367
  • Upstream: a test service that records the request body
Lingua principale
Go
Stelle
85
Fork
142
Merge medio
1g 6h
PR unite (30g)
250

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

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 wso2/api-platform

Tutte le issue di wso2/api-platform

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.