Tsukikage7 commented on code in PR #1527: URL: https://github.com/apache/dubbo-admin/pull/1527#discussion_r4183458987
########## ui-vue3/src/utils/JsonUtil.ts: ########## @@ -0,0 +1,24 @@ +/* + * 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. + */ + +import { isSafeNumber, parse } from 'lossless-json' + +export function parseJsonWithSafeNumbers<T>(text: string): T { + return parse(text, undefined, { + parseNumber: (value) => (isSafeNumber(value) ? parseFloat(value) : value) + }) as T +} Review Comment: Agreed. The generic return type promises a shape the parser does not validate, and unsafe numeric values can become strings. Changed the return type to `unknown` and removed the cast in 9615120. ########## ui-vue3/src/views/resources/services/tabs/debug.vue: ########## @@ -555,9 +556,11 @@ async function handleInvoke() { } let args: any[] try { - args = JSON.parse(requestValue.value) - if (!Array.isArray(args)) { - args = [args] + const parsedArgs = parseJsonWithSafeNumbers<unknown>(requestValue.value) + if (Array.isArray(parsedArgs)) { + args = parsedArgs + } else { + args = [parsedArgs] } Review Comment: Addressed in 9615120. Removed the generic argument and retained the existing `Array.isArray` narrowing and scalar wrapping. The local arguments array now uses `unknown[]`; request behavior is unchanged. ########## ui-vue3/src/utils/JsonUtil.spec.ts: ########## @@ -0,0 +1,36 @@ +/* + * 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. + */ + +import { describe, expect, it } from 'vitest' +import { parseJsonWithSafeNumbers } from './JsonUtil' + +describe('parseJsonWithSafeNumbers', () => { + it('preserves integers outside the JavaScript safe range', () => { + const args = parseJsonWithSafeNumbers<unknown[]>('[1694620889412087810]') Review Comment: Addressed in 9615120. Removed the generic arguments. These tests compare complete values, so no local cast is needed. Added an `unknown` type assertion and coverage for nested unsafe integers and positive/negative safe-number boundaries. The utility and spec also pass a separate strict TypeScript check, so the type assertion is checked in addition to running Vitest. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
