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

未关闭
#4,467 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
53/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
go
领域
api

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Go
星标
85
派生
142
平均合并
1 天 7 小时
30 天内合并 PR
255

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

wso2/api-platform 的其他 Issue

查看 wso2/api-platform 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。