Skip to content

Commit

Permalink
Fix output with C locale
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
faho committed Mar 11, 2020
1 parent acad9b0 commit 1a063fe
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(-1)) {
debug(3, L"Tried to print invalid wide character string");
Expand Down

0 comments on commit 1a063fe

Please sign in to comment.