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
fix issue 11431 - std.file.slurp fails with Windows newlines #6680
Conversation
Thanks for your pull request and interest in making D better, @bbasile! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#6680" |
std/file.d
Outdated
|
||
auto app = appender!(typeof(return))(); | ||
ElementType!(typeof(return)) toAdd; | ||
auto f = File(filename); | ||
scope(exit) f.close(); | ||
foreach (line; f.byLine()) | ||
{ | ||
line = stripRight(line, ['\r']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
['\r']
doesn't compile in @nogc
. Maybe just use "\r"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fortunately the right overload exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a pragmatic approach in line with readText
/splitLines
. A more pedantically correct one would be, considering that the root of the problem is byLine
's default separator
argument being '\n'
, to allow specifying a separator to pass to byLine
.
One potential point of concern is breaking code which worked around the previous behavior. I.e., this code currently works but will fail with this patch:
write(deleteme, "10\r\n20\r\n");
assert(slurp!int(deleteme, "%d ") == [10, 20]);
(Note the space after %d
.)
What do you think about changing line 5109 instead, from enforce(line.empty,
to enforce(line.stripRight("\r").empty,
?
No description provided.