From 07f2d33085e686c8cd4dab499799380f74e7198d Mon Sep 17 00:00:00 2001 From: Jeongho Nam Date: Fri, 11 Oct 2024 18:11:31 +0900 Subject: [PATCH] Fix #1036: emoji case in the `protobuf` --- package.json | 2 +- src/functional/$strlen.ts | 8 +------- .../issues/test_issue_1306_protobuf_emoji.ts | 18 ++++++++++++++++++ ...st_issue_1321_protobuf_reserved_keyword.ts} | 2 +- 4 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 test/src/features/issues/test_issue_1306_protobuf_emoji.ts rename test/src/features/issues/{test_issue_1321_private_key_in_protobuf.ts => test_issue_1321_protobuf_reserved_keyword.ts} (83%) diff --git a/package.json b/package.json index f95cf1995c..fd7e55693d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "typia", - "version": "6.11.1", + "version": "6.11.2", "description": "Superfast runtime validators with only one line", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/src/functional/$strlen.ts b/src/functional/$strlen.ts index 1ad41b5b50..3a940f9542 100644 --- a/src/functional/$strlen.ts +++ b/src/functional/$strlen.ts @@ -1,7 +1 @@ -export const $strlen = (s: string): number => { - let b: number; - let i: number; - let c: number; - for (b = i = 0; (c = s.charCodeAt(i++)); b += c >> 11 ? 3 : c >> 7 ? 2 : 1); - return b; -}; +export const $strlen = (str: string): number => new Blob([str]).size; diff --git a/test/src/features/issues/test_issue_1306_protobuf_emoji.ts b/test/src/features/issues/test_issue_1306_protobuf_emoji.ts new file mode 100644 index 0000000000..bb825fb826 --- /dev/null +++ b/test/src/features/issues/test_issue_1306_protobuf_emoji.ts @@ -0,0 +1,18 @@ +import typia from "typia"; + +import { TestValidator } from "../../helpers/TestValidator"; + +interface ITest { + test: string; +} + +export const test_issue_1306_protobuf_emoji = (): void => { + const input: ITest = { + test: "🫢", + }; + const encoded: Uint8Array = typia.protobuf.encode(input); + const decoded: ITest = typia.protobuf.decode(encoded); + + TestValidator.equals("decoded")(decoded)(input); + TestValidator.equals("length")(decoded.test.length)(input.test.length); +}; diff --git a/test/src/features/issues/test_issue_1321_private_key_in_protobuf.ts b/test/src/features/issues/test_issue_1321_protobuf_reserved_keyword.ts similarity index 83% rename from test/src/features/issues/test_issue_1321_private_key_in_protobuf.ts rename to test/src/features/issues/test_issue_1321_protobuf_reserved_keyword.ts index d7064d1457..ce577b5f33 100644 --- a/test/src/features/issues/test_issue_1321_private_key_in_protobuf.ts +++ b/test/src/features/issues/test_issue_1321_protobuf_reserved_keyword.ts @@ -6,7 +6,7 @@ type MyObj = { private: boolean | null; }; -export const test_issue_1321_private_key_in_protobuf = (): void => { +export const test_issue_1321_protobuf_reserved_keyword = (): void => { const input: MyObj = { private: true, };