Skip to content

Commit bc0938d

Browse files
committed
only check parts of the string that are not going to get truncated
1 parent fc41b95 commit bc0938d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

apps/webapp/app/v3/otlpExporter.server.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,17 +803,19 @@ function truncateAndDetectUnpairedSurrogate(str: string, maximumLength: number):
803803
return truncatedString;
804804
}
805805

806-
const ASCII_ONLY_REGEX = /^[\x00-\x7F]*$/;
806+
const ASCII_ONLY_REGEX = /^[\p{ASCII}]*$/u;
807807

808808
function smartTruncateString(str: string, maximumLength: number): string {
809809
if (!str) return "";
810810
if (str.length <= maximumLength) return str;
811811

812-
if (ASCII_ONLY_REGEX.test(str)) {
812+
const checkLength = Math.min(str.length, maximumLength * 2 + 2);
813+
814+
if (ASCII_ONLY_REGEX.test(str.slice(0, checkLength))) {
813815
return str.slice(0, maximumLength);
814816
}
815817

816-
return [...str].slice(0, maximumLength).join("");
818+
return [...str.slice(0, checkLength)].slice(0, maximumLength).join("");
817819
}
818820

819821
function hasUnpairedSurrogateAtEnd(str: string): boolean {

0 commit comments

Comments
 (0)