-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fs::File.read_to_string(...) appends newline character #6943
Comments
I suspect your file probably contains an extra newline character :) As an aside, |
I did check for that :). It does not |
I couldn't see such a behavior in this program: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=0e7fc9932d5c459ccc7d52a07bab198d |
Have you tried with There really is nowhere for Tokio to insert a spurious newline character in the code you shared. I still think your file has a newline character, and that you're doing something wrong when checking it. I'm going to close this. If you want this issue reopened, I'm going to need really really compelling evidence that your file really does not have a newline character at the end. Be aware that text editors usually don't show the last newline character as an additional empty line. Please see this SO question. |
You were right, I'm sorry. It's just surprisingly hard to get this right. I did not expect neovim to do nasty things like inserting invisible newlines (it only shows line numbers where content is, and there is no line number on the line after my content, but sure enough, there's a newline character at the end of the first line). It gets worse, as it's even harder to test if that newline is there. echo "newlinetest" > testnewline;
echo "/$(cat testnewline)/"
# -> /newlinetest/ The newline is there in the example above, but Best way I found so far to not have it there is echo -n "whatever you want" > "wherever_you_want" or perhaps even better printf '%s' "whatever you want" > "wherever you want" as taken from here |
Version
List the versions of all
tokio
crates you are using. The easiest way to getthis information is using
cargo tree
subcommand:cargo tree | grep tokio
1.41.0
Platform
The output of
uname -a
(UNIX), or version and 32 or 64-bit (Windows)Linux nixos 6.6.32 #1-NixOS SMP PREEMPT_DYNAMIC Sat May 25 14:22:56 UTC 2024 x86_64 GNU/Linux
Description
Enter your issue details here.
One way to structure the description:
[short summary of the bug]
I'm reading a file using
Now,
master_key
has an extra newline at the end, which breaks downstream codeI expected to see this happen:
master_key
should contain exactly the contents of the fileInstead, this happened: it contains an extra newline at the end
The text was updated successfully, but these errors were encountered: