diff --git a/javascript/packages/core/lib/meta/TypeMeta.ts b/javascript/packages/core/lib/meta/TypeMeta.ts index 091800c729..08939ed7ef 100644 --- a/javascript/packages/core/lib/meta/TypeMeta.ts +++ b/javascript/packages/core/lib/meta/TypeMeta.ts @@ -33,8 +33,8 @@ const fieldEncoder = new MetaStringEncoder("$", "_"); const fieldDecoder = new MetaStringDecoder("$", "_"); const pkgEncoder = new MetaStringEncoder(".", "_"); const pkgDecoder = new MetaStringDecoder(".", "_"); -const typeNameEncoder = new MetaStringEncoder("$", "."); -const typeNameDecoder = new MetaStringDecoder("$", "."); +const typeNameEncoder = new MetaStringEncoder("$", "_"); +const typeNameDecoder = new MetaStringDecoder("$", "_"); const COMPRESS_META_FLAG = 1n << 8n; const RESERVED_META_FLAGS = 0b111n << 9n; diff --git a/javascript/test/typemeta.test.ts b/javascript/test/typemeta.test.ts index effd162278..09dd047519 100644 --- a/javascript/test/typemeta.test.ts +++ b/javascript/test/typemeta.test.ts @@ -2952,6 +2952,32 @@ describe("typemeta", () => { expect(result).toBeInstanceOf(EmptyWrapper); }); + + // Bytes a spec-conformant peer (for example Java) emits for a named struct + // with namespace "example", typeName "Type_1", and one fixed int32 field + // "v". The type name uses LOWER_UPPER_DIGIT_SPECIAL, where char value 63 is + // "_" per the spec's type-name special-char set ("$", "_"). + const specTypeNameMetaBytes = new Uint8Array([ + 16, 64, 45, 74, 58, 106, 49, 48, 161, 21, 18, 224, 99, 214, 64, 22, 90, 193, 226, 127, 168, 64, + 4, 84, + ]); + + test("decodes spec char value 63 in type names as underscore", () => { + const reader = new BinaryReader({}); + reader.reset(specTypeNameMetaBytes); + const decoded = TypeMeta.fromBytes(reader); + expect(decoded.getTypeName()).toBe("Type_1"); + }); + + test("encodes underscore type names with the spec charset", () => { + const meta = TypeMeta.fromTypeInfo( + Type.struct( + { namespace: "example", typeName: "Type_1" }, + { v: Type.int32({ encoding: "fixed" }) }, + ), + ); + expect(Array.from(meta.toBytes())).toEqual(Array.from(specTypeNameMetaBytes)); + }); }); function typeMetaBodyOffset(bytes: Uint8Array) {