[Bug]: json-xml-mediator policy turns XML text that looks like a number into a JSON number

Abierto
#4,467 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
53/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
go
Área
api

Línea de trabajo

Start by locating the json-xml-mediator policy implementation and its XML-to-JSON conversion tests; the issue does not name specific files. Trace where XML text values are trimmed and inferred as numbers or booleans, then check how the policy documentation's Example 1 represents string values. Done means XML text such as 02134 and 1.10 reaches the client unchanged as JSON strings for both backend responses and XML requests.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

When the policy converts XML to JSON, it guesses a type for each text value. Text that parses as a number becomes a JSON number, and true and false become booleans. Surrounding whitespace is trimmed first.

XML text has no type, so the guess loses data. Leading zeros and trailing zeros disappear. A ZIP code 02134 becomes 2134, and a version 1.10 becomes 1.1. This applies to backend responses and to XML requests alike.

The policy documentation does not describe the guess. Its Example 1 shows an order ID kept as the string "12345".

Expected Behaviour

Text reaches the client unchanged, as a JSON string: {"order":{"version":"1.10","zip":"02134"}}.

Actual Behaviour

The client receives {"order":{"version":1.1,"zip":2134}}.

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. Have the backend answer application/xml with <order><zip>02134</zip><version>1.10</version></order>.
  3. Send {"sku":"W-1"} with Content-Type: application/json. The client receives {"order":{"version":1.1,"zip":2134}}.
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 scripted to answer the XML above
Lenguaje dominante
Go
Estrellas
85
Forks
142
Merge medio
1 d 7 h
PR fusionados (30 d)
255

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de wso2/api-platform

Todos los issues de wso2/api-platform

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.