flomesh-io / pipy

Pipy is a programmable proxy for the cloud, edge and IoT.
https://flomesh.io/pipy
Other
743 stars 70 forks source link

Pjs object property integer number key will be converted to float string #130

Closed leoatpolaris closed 1 year ago

leoatpolaris commented 1 year ago

Bug Report

Pjs object property integer number key will be converted to float string

Pipy Version

Version     : nightly-202211132335
Commit      : 08f33aae4a5d2a943af8b574f0d27e4d4fb3a13e
Commit Date : Mon, 14 Nov 2022 11:04:23 +0800
Host        : Linux-3.10.0-1160.76.1.el7.x86_64 x86_64
OpenSSL     : OpenSSL 1.1.1q  5 Jul 2022
Builtin GUI : Yes
Samples     : Yes

Steps to reproduce

pipy({
  cfg: { 1: "a", 2: "b" }
})

.task('3s')
  .onStart(() => new Message)
  .handleMessage(() => console.log(cfg))
$ pipy test.js

Output


2022-11-14 22:53:07.327 [INF] [config]
2022-11-14 22:53:07.327 [INF] [config] Module /test.js
2022-11-14 22:53:07.327 [INF] [config] ===============
2022-11-14 22:53:07.327 [INF] [config]
2022-11-14 22:53:07.327 [INF] [config]  [Task #1 (3s)]
2022-11-14 22:53:07.327 [INF] [config]  ----->|
2022-11-14 22:53:07.327 [INF] [config]        |
2022-11-14 22:53:07.327 [INF] [config]       handleMessage -->|
2022-11-14 22:53:07.327 [INF] [config]                        |
2022-11-14 22:53:07.327 [INF] [config]  <---------------------|
2022-11-14 22:53:07.327 [INF] [config]  
2022-11-14 22:53:07.327 [INF] [object Literal] {"1.000000":"a","2.000000":"b"}
pajama-coder commented 1 year ago

Thanks for reporting the issue. In fact, this problem can be reproduced as simply as:

$ pipy -e "{1:'a',2:'b'}"
[object Literal]
{"1.000000":"a","2.000000":"b"}

But anyway, I'll look into it shortly.

naqvis commented 1 year ago

verified and confirm that commit#https://github.com/flomesh-io/pipy/commit/cd71904fc0b5ef9bba8776b632e9391bd0ab1d75 fixes this.

➜  ./pipy -e "{1:'a',2:'b'}"
[object Literal]
{"1":"a","2":"b"}
2022-11-21 23:42:32.829 [ERR] [pjs] Script did not result in a Configuration
2022-11-21 23:42:32.830 [INF] [shutdown] Shutting down...
2022-11-21 23:42:32.830 [INF] [shutdown] Stopped.
Done.