Skip to content

Commit cb5080d

Browse files
committed
Ticket #4801: Improved handling of invalid UTF-8 in the prompt, part 2/2
Do not filter out invalid UTF-8 components, instead let them pass through as-is. This will result in mc converting them to a replacement symbol. Signed-off-by: Egmont Koblinger <[email protected]>
1 parent 86f3eb4 commit cb5080d

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

lib/terminal.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,9 @@ strip_ctrl_codes (char *s)
237237
r++;
238238
}
239239
else
240-
{
241-
// FIXME Improve the handling of invalid UTF-8, insert a replacement symbol (#4801)
242-
const char *n = str_cget_next_char_safe (r);
243-
244-
if (str_isprint (r))
245-
{
246-
memmove (w, r, n - r);
247-
w += n - r;
248-
}
249-
r = n;
250-
}
240+
// Copy byte by byte, thereby letting mc use its standard mechanism to denote invalid
241+
// UTF-8 sequences. See #4801.
242+
*(w++) = *(r++);
251243
}
252244

253245
*w = '\0';

tests/lib/terminal.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@ START_TEST (test_strip_ctrl_codes2)
9494
memcpy (s, s_orig, sizeof (s_orig));
9595

9696
char *actual = strip_ctrl_codes (s);
97-
const char *expected = "\342\235\244 bcdfghjklm";
9897

99-
ck_assert_str_eq (actual, expected);
98+
ck_assert_str_eq (actual, s_orig);
10099
g_free (s);
101100
}
102101
END_TEST

0 commit comments

Comments
 (0)