From c865e0dc78dc476399f1fe172617294614623ba1 Mon Sep 17 00:00:00 2001 From: "K. Lange" Date: Wed, 6 Mar 2024 09:47:07 +0900 Subject: [PATCH] Fix oops in str.__repr__, how did tests not catch that --- src/obj_str.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/obj_str.c b/src/obj_str.c index 3c22dc2..efda7d1 100644 --- a/src/obj_str.c +++ b/src/obj_str.c @@ -893,16 +893,6 @@ KRK_Method(str,__repr__) { for (char * c = AS_CSTRING(argv[0]); c < end; ++c) { unsigned char ch = *c; - if (ch < ' ' || ch == 0x7F) { - pushStringBuilder(&sb,'\\'); - pushStringBuilder(&sb,'x'); - char hex[3]; - snprintf(hex, 3, "%02x", (unsigned char)*c); - pushStringBuilder(&sb,hex[0]); - pushStringBuilder(&sb,hex[1]); - continue; - } - int addSlash = 0; switch (ch) { /* XXX: Other non-printables should probably be escaped as well. */ @@ -917,7 +907,17 @@ KRK_Method(str,__repr__) { case '\t': addSlash = 1; ch = 't'; break; case '\v': addSlash = 1; ch = 'v'; break; case 27: addSlash = 1; ch = '['; break; - default: break; + default: + if (ch < ' ' || ch == 0x7F) { + pushStringBuilder(&sb,'\\'); + pushStringBuilder(&sb,'x'); + char hex[3]; + snprintf(hex, 3, "%02x", (unsigned char)*c); + pushStringBuilder(&sb,hex[0]); + pushStringBuilder(&sb,hex[1]); + continue; + } + break; } if (addSlash) krk_pushStringBuilder(&sb,'\\'); krk_pushStringBuilder(&sb,ch);