square / square/wire

JSON generated from Swift message with >=16 fields exposes `storage` field

Open
#1,989 3 comments 0 reactions 1 assignee View on GitHub

@efirestone is already working on this.

Since Jul 30, 2021.

bug lang/swift
Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

Using this protobuf message:

message ManyFields {
  int32 field_1 = 1;
  int32 field_2 = 2;
  int32 field_3 = 3;
  int32 field_4 = 4;
  int32 field_5 = 5;
  int32 field_6 = 6;
  int32 field_7 = 7;
  int32 field_8 = 8;
  int32 field_9 = 9;
  int32 field_10 = 10;
  int32 field_11 = 11;
  int32 field_12 = 12;
  int32 field_13 = 13;
  int32 field_14 = 14;
  int32 field_15 = 15;
  int32 field_16 = 16;
  int32 field_17 = 17;
  int32 field_18 = 18;
}

Then create and object and encode to json (similar than in your JsonLitmusTest.swift):

let manyFieldsWire: ManyFields = ManyFields(
            field_1: 1, field_2: 2, field_3: 3, field_4: 4, field_5: 5, field_6: 6, field_7: 7,
            field_8: 8, field_9: 9, field_10: 10, field_11: 11, field_12: 12, field_13: 13,
            field_14: 14, field_15: 15, field_16: 16, field_17: 17, field_18: 18 )
         // Serialize to JSON
        let manyFieldsJsonWireData = try! JSONEncoder().encode(manyFieldsWire)
        let manyFieldsJsonWire = String(data: manyFieldsJsonWireData, encoding: .utf8)!
        print("manyFields JSON Wire:\n" + manyFieldsJsonWire)
}

Produces the following JSON:

{
  "storage": {
    "field_14": 14,
    "field_5": 5,
    "field_15": 15,
    "field_2": 2,
    "field_7": 7,
    "field_10": 10,
    "field_16": 16,
    "field_4": 4,
    "field_11": 11,
    "field_9": 9,
    "field_17": 17,
    "field_1": 1,
    "field_6": 6,
    "field_12": 12,
    "field_18": 18,
    "field_13": 13,
    "field_3": 3,
    "field_8": 8
  }
}

As you can see there's a top-level storage in the JSON that in my opinion shouldn't be exposed.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.