From 1a063fe3c1be9c5eb78620233dc31c0dadb74ff5 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 11 Mar 2020 20:29:12 +0100 Subject: [PATCH] Fix output with C locale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If given a prompt that includes a non-ascii char and a C locale, fish currently fails to properly display it. So you set `function fish_prompt; echo 😃; end` and it shows empty space. While the underlying cause is obviously using a C locale and non-C characters to begin with, this is an unacceptable failure mode. Apparently I misunderstood wcstombs, so I inadvertently broke this in 2b0b3d3 while trying to fix 5134949's crash. Just return the offending bit to pre-5134949 levels, so instead of an infinite recursion we just call a lame function a couple of times. --- src/output.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/output.cpp b/src/output.cpp index e1bcd7cdb..19c3533bb 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -402,6 +402,11 @@ int outputter_t::writech(wint_t ch) { void outputter_t::writestr(const wchar_t *str) { assert(str && "Empty input string"); + if (MB_CUR_MAX == 1) { + // Single-byte locale (C/POSIX/ISO-8859). + while (*str) writech(*str++); + return; + } size_t len = wcstombs(nullptr, str, 0); // figure amount of space needed if (len == static_cast(-1)) { debug(3, L"Tried to print invalid wide character string");