Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with unicode handling in proto map keys #416

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

jquirke
Copy link
Contributor

@jquirke jquirke commented Jun 19, 2024

In a map where the key is a string, containing unicode characters, yab may fail to properly decode the protobuf message.

 // User Tags, key is tag name while value is the actual tag
    map<string, common.CustomerTag> tags = 11

This is because the JSON string written by jump/protoreflect's MarshalJSONPB method doesn't correctly escape unicode characters.

Inspecting the intermediate JSON we see invalid JSON:

 "AU_P\342\200\231NutAsianKitchen_2024feb05-T": { ... }

This issue was fixed in jhump/protoreflect#481 in v1.10.2, however we upgrade the dependency to 1.15.6, the latest usable before a breaking change to protobuf and a requirement to use go1.19.

Before

$ yab .... | jq keys
Failed while parsing response: invalid character '3' in string escape code
Process 97171 has exited with status 1

After

$ yab .... | jq keys
[
  "body",
  "headers"
]

In a map where the key is a string, containing unicode characters,
yab may fail to properly decode the protobuf message.
```
 // User Tags, key is tag name while value is the actual tag
    map<string, common.CustomerTag> tags = 11
```

This is because the JSON string written by jump/protoreflect's
MarshalJSONPB method doesn't correctly escape unicode characters.

Inspecting the intermediate JSON we see invalid JSON:

```
 "AU_P\342\200\231NutAsianKitchen_2024feb05-T": { ... }
```

This issue was fixed in jhump/protoreflect#481
in v1.10.2, however we upgrade the dependency to 1.15.6, the last
before a breaking change to protobuf and a requirement to use go1.19.

We can address this in a future PR.

Tested:

Before
```
$ yab .... | jq keys
Failed while parsing response: invalid character '3' in string escape code
Process 97171 has exited with status 1
```

After

```
$ yab .... | jq keys
[
  "body",
  "headers"
]
```
                    `
@jquirke jquirke marked this pull request as draft June 19, 2024 10:11
In grpc/grpc-go#5197, there was a major change
to server reflection, specifically:

"If a [DescriptorResolver] is not present, protoregistry.GlobalFiles
will be used. "

It so happens that in simple.pb in the testdata there *is* a service
called Foo and Bar and this is why these tests are now surprisingly
passing instead of failing with unknown method errors.

We work around this by creating method names that are unlikely to exist.
@jquirke jquirke marked this pull request as ready for review June 20, 2024 02:50
Copy link
Contributor

@jronak jronak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait for the internal repository to remove version clamp on protoreflect, otherwise LGTM. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants