From 468b1a434681f98ea64d399abce7ddd8c605617d Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 28 Jan 2023 18:50:32 +0000 Subject: Fix "format %c 0x10000041", should give the same answer as in Tcl 8.6 (Handling of TCL_COMBINE flag should not be visible at script level) --- generic/tclStringObj.c | 3 +++ tests/format.test | 3 +++ 2 files changed, 6 insertions(+) diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index a041d4c..e1376f4 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2130,6 +2130,9 @@ Tcl_AppendFormatToObj( if (TclGetIntFromObj(interp, segment, &code) != TCL_OK) { goto error; } + if ((unsigned)code > 0x10FFFF) { + code = 0xFFFD; + } length = Tcl_UniCharToUtf(code, buf); #if TCL_UTF_MAX < 4 if ((code >= 0xD800) && (length < 3)) { diff --git a/tests/format.test b/tests/format.test index c47774a..8cabbf1 100644 --- a/tests/format.test +++ b/tests/format.test @@ -402,6 +402,9 @@ test format-8.26 {Undocumented formats} -body { test format-8.27 {Undocumented formats} -constraints pointerIs64bit -body { format "%p %#llx" [expr {2**33}] [expr {2**33}] } -result {0x200000000 0x200000000} +test format-8.28 {Internal use of TCL_COMBINE flag should not be visiable at script level} { + format %c 0x10000041 +} \uFFFD test format-9.1 {long result} { set a {1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1 2 3 4 5 6 7 8 9 0 a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z} -- cgit v0.12