Skip to content

Commit

Permalink
Match typeUrls with leading slash
Browse files Browse the repository at this point in the history
  • Loading branch information
grod220 committed Nov 17, 2023
1 parent fd56d4c commit d331a07
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/protobuf-test/src/google/protobuf/any.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ describe("google.protobuf.Any", () => {
expect(got.is("type.googleapis.com/google.protobuf.Value")).toBe(false);
});

test(`matches type name with leading slash`, () => {
const any = new Any({ typeUrl: "/google.protobuf.Value" });
expect(any.is(Value)).toBe(true);
});

test(`is returns false for an empty Any`, () => {
const got = new Any();

Expand All @@ -106,6 +111,21 @@ describe("google.protobuf.Any", () => {
expect(unpacked.kind.value).toBe(1);
});

test(`unpack correctly unpacks a message with a leading slash type url in the registry`, () => {
const typeRegistry = createRegistry(Value);
const val = new Value({
kind: { case: "numberValue", value: 1 },
});
const { value } = Any.pack(val);
const any = new Any({ typeUrl: "/google.protobuf.Value", value });

const unpacked = any.unpack(typeRegistry) as Value;

expect(unpacked).toBeDefined();
expect(unpacked.kind.case).toBe("numberValue");
expect(unpacked.kind.value).toBe(1);
});

test(`unpack returns undefined if message not in the registry`, () => {
const typeRegistry = createRegistry();
const val = new Value({
Expand Down
2 changes: 1 addition & 1 deletion packages/protobuf/src/google/protobuf/any_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d331a07

Please sign in to comment.