RockteMQ-AI commented on code in PR #4759:
URL: 
https://github.com/apache/rocketmq-dashboard/pull/4759#discussion_r4062167010


##########
rmqctl/internal/studio/client.go:
##########
@@ -150,7 +150,12 @@ func (c Client) request(ctx context.Context, target 
Target, method string, path
        if !hasJSONData(envelope.Data) {
                return nil
        }
-       if err := json.Unmarshal(envelope.Data, out); err != nil {
+       // Passthrough commands decode into an `any`, where encoding/json would 
represent every
+       // number as float64 and silently corrupt int64 values beyond 2^53 
(RocketMQ offsets and
+       // timestamps). UseNumber keeps the literal; decoding into typed struct 
fields is unaffected.

Review Comment:
   Using `json.NewDecoder` with `UseNumber()` is the correct fix for preserving 
int64 precision in passthrough payloads. When decoding into `any`, 
`encoding/json` defaults to `float64`, which silently corrupts values beyond 
2^53 (the classic JavaScript safe integer boundary). `UseNumber()` keeps the 
literal representation as `json.Number`, which downstream code can convert to 
`int64` without loss.



##########
rmqctl/internal/studio/client_test.go:
##########
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package studio
+
+import (
+       "context"
+       "encoding/json"
+       "net/http"
+       "net/http/httptest"
+       "strings"
+       "testing"
+)
+
+// The passthrough commands decode the studio payload into an `any`, where 
encoding/json
+// would represent every number as float64 and silently corrupt int64 values 
beyond 2^53
+// (RocketMQ offsets and timestamps). The client must keep the literal via 
json.Number.
+func TestRequestPreservesLargeIntegersInPassthroughPayload(t *testing.T) {
+       server := httptest.NewServer(http.HandlerFunc(func(w 
http.ResponseWriter, r *http.Request) {
+               w.Header().Set("Content-Type", "application/json")
+               _, _ = 
w.Write([]byte(`{"code":200,"message":"ok","data":{"items":[{"msgOffset":9007199254740993}]}}`))

Review Comment:
   Good test choice — `9007199254740993` (2^53 + 1) is the canonical precision 
boundary value. The test directly validates that the passthrough path preserves 
the exact integer, which is the core guarantee this fix provides.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to