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

Đang mở Phù hợp với người mới
#4,465 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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
68/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
api, backend

Hướng nghiên cứu

Bắt đầu bằng cách tìm mã của policy json-xml-mediator định dạng các số JSON bằng động từ %g của Go; issue xác định policy và hành vi bị ảnh hưởng nhưng không nêu tệp hay bài kiểm thử nào. Kiểm tra cách các bài kiểm thử policy hiện có bao quát việc chuyển đổi JSON sang XML, sau đó thêm các trường hợp cho 1234567 và 0.00001. Công việc hoàn tất khi các phần tử XML đó giữ nguyên giá trị thập phân thay vì dùng ký pháp số mũ và các bài kiểm thử liên quan đều đạt.

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

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

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.