Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

JS Unexpected behavior when serializing/deserializing

未關閉
#51 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
25/100
Issue 類型
缺陷
描述清晰度
需要釐清
活躍度
停滯
技術堆疊
javascript

研究方向

重現 issue 中所示的 setPkid/serializeBinary/deserializeBinary 序列。追蹤 MyMessage setter 以及序列化/反序列化進入點,以找出數值在哪裡變成空字串。當預期的型別處理有一個經 maintainer 核准的 fix,或有一項已記錄的決定時,即視為完成。

由索引模型根據 Issue 內容生成。

描述

bug javascript port-fix triaged

Hello opening this issue because I've seen an unexpected behavior and want to discuss about it and see what's the best pattern

Given the following message:

message MyMessage {
    String pkid = 1;
}

If I set a number field into pkid, I'm able to retrieve it correctly. Once I serialize and then deserialize the message, the value gets coerced as an empty string:

> protoConfig.setPkid(123);
> protoConfig.getPkid();
123
> MyMessage.deserializeBinary((protoConfig.serializeBinary())).getPkid()
""

I wasn't expecting the field to be transformed silently once the message is serialized. What I would expect from order of preference:

  1. Setting the field with setPkid to crash (or a warning) because the type is not what was expected
  2. Serialization crashing (or a warning) because the type is not expected
  3. Coercing the type using toString which would set it to '123'

I understand suggested behaviors may have performance implications but I'm not sure what's the reason of current behavior because this still forces the user to do type checks before setting fields in a protobuf message when using javascript? IMO silently changing the value of a field when serializing a message is dangerous and I would aim for correctness of data first.

主要語言
JavaScript
星號
471
分支
91
平均合併
1 天 12 小時
30 天內合併 PR
6

環境準備

我們還沒有檢查這個專案的環境設定檔。先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

protocolbuffers/protobuf-javascript 的其他 Issue

查看 protocolbuffers/protobuf-javascript 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。