Skip to content

Commit

Permalink
Merge pull request #743 from samchon/features/stringify
Browse files Browse the repository at this point in the history
Fix #736 - bug of undefined `length` problem.
  • Loading branch information
samchon authored Aug 4, 2023
2 parents 5d7b203 + 0eefd45 commit 8178918
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typia",
"version": "4.1.15",
"version": "4.1.16",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions packages/typescript-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "4.1.15",
"version": "4.1.16",
"description": "Superfast runtime validators with only one line",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -68,7 +68,7 @@
},
"homepage": "https://typia.io",
"dependencies": {
"typia": "4.1.15"
"typia": "4.1.16"
},
"peerDependencies": {
"typescript": ">= 4.7.4"
Expand Down
4 changes: 3 additions & 1 deletion src/functional/$string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
*/
export const $string = (str: string): string => {
if (STR_ESCAPE.test(str) === false) return `"${str}"`;
if (str.length > 41) return JSON.stringify(str);

const length: number = str.length;
if (length > 41) return JSON.stringify(str);

let result = "";
let last = -1;
Expand Down
14 changes: 14 additions & 0 deletions test/features/issues/test_issue_long_string_stringify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import typia from "typia";

import { RandomGenerator } from "typia/lib/utils/RandomGenerator";

export const test_issue_long_string_stringify = (): void => {
const str: string = RandomGenerator.string(1000);
const stringified: string = typia.stringify(str);
const decoded: string = JSON.parse(stringified);

if (str !== decoded)
throw new Error(
`Bug on typia.stringify(): failed to stringify long string.`,
);
};
13 changes: 13 additions & 0 deletions test/generated/output/issues/test_issue_long_string_stringify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import typia from "typia";

import { RandomGenerator } from "typia/lib/utils/RandomGenerator";

export const test_issue_long_string_stringify = (): void => {
const str: string = RandomGenerator.string(1000);
const stringified: string = typia.stringify(str);
const decoded: string = JSON.parse(stringified);
if (str !== decoded)
throw new Error(
`Bug on typia.stringify(): failed to stringify long string.`,
);
};

0 comments on commit 8178918

Please sign in to comment.