-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
echo
does not print emoji given escape sequence \xf0\x9f\x98\x82
#6741
Comments
I'm glad to submit a PR. ProposalI identify the issue as returning coreutils/src/uu/echo/src/echo.rs Line 42 in a0d258d
A /// A buffer used to interpret bytes as Unicode characters.
struct TryUnicodeBuffer {
bytes: [u8; 4],
len: usize,
}
impl TryUnicodeBuffer {
/// Push and attempt to convert the buffer into Unicode characters, which
/// are written to `output`. Panic if the buffer is already full, which
/// shouldn't happen normally. After `push`, it's guaranteed that the
/// remaining bytes do not make up a valid utf-8 character.
fn push(&mut self, i: u8, mut output: impl Write) -> io::Result<()> {}
/// Try to interpret the bytes started at position `start` as a Unicode
/// character.
fn to_char(&self, start: usize) -> Option<char> {}
/// Clear the remaining (invalid) bytes and replace with the replacement
/// characters if not empty.
fn clear(&mut self, mut output: impl Write) -> io::Result<()> {}
/// Clear and push something that can be interpreted as a Unicode
/// character.
fn clear_push(&mut self, i: impl Into<char>, mut output: impl Write) -> io::Result<()> {}
} Only Test cases
|
Bug was reported, with root cause analysis, by kkew3 Added tests were derived from test cases provided by kkew3 See uutils#6741
#6803 should fix this. I went with a simpler fix. Since everything is being printed to stdout, which is obviously not restricted to UTF-8 data, the escape codes can just be printed out byte by byte, without trying to keep track of whether the output is valid UTF-8. |
Yeah, it's definitely a better fix. It also comes to my mind that all of these, tested on ubuntu 22.04, Great! I'll close this issue. |
A nice way to debug these issues is to use
https://github.com/sharkdp/bat Otherwise, yes, you can't really tell what's going on when you're dealing with weird/non-UTF-8 output. Technically I don't think this issue should be closed until a PR resolving the bug has been merged, but I'll be checking in on my PR periodically until it's merged, so it shouldn't matter much. |
Bug was reported, with root cause analysis, by kkew3 Added tests were derived from test cases provided by kkew3 See uutils#6741
* echo: handle multibyte escape sequences Bug was reported, with root cause analysis, by kkew3 Added tests were derived from test cases provided by kkew3 See #6741 * Use concrete type * Fix MSRV issue * Fix non-UTF-8 argument handling * Fix MSRV issue * Fix Clippy violation * Fix compiler warning * Address PR comments * Add MSRV TODO comments * echo: use stdout_only_bytes instead of stdout_is_bytes --------- Co-authored-by: Daniel Hofstetter <[email protected]>
How to reproduce
cargo run -p uu_echo -- -e '\xf0\x9f\x98\x82'
gives
�
.Expected behavior
Under Ubuntu 22.04, with
/bin/echo --version
:the output is
😂
, given command/bin/echo -e '\xf0\x9f\x98\x82'
.The text was updated successfully, but these errors were encountered: