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

Đang mở
#4,467 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
53/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
api

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Go
Star
85
Fork
142
Merge trung bình
1 ngày 7 giờ
Pull request đã merge (30 ngày)
255

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của wso2/api-platform

Tất cả issue của wso2/api-platform

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.