Skip to content
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

Merged
merged 2 commits into from Aug 26, 2018
Merged

fix issue 11431 - std.file.slurp fails with Windows newlines #6680

merged 2 commits into from Aug 26, 2018

Conversation

ghost
Copy link

@ghost ghost commented Aug 25, 2018

No description provided.

@ghost ghost requested a review from CyberShadow as a code owner August 25, 2018 17:11
@dlang-bot
Copy link
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Auto-close Bugzilla Severity Description
11431 normal std.file.slurp fails with Windows newlines

Testing this PR locally

If 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']);
Copy link
Member

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"?

Copy link
Author

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.

Copy link
Member

@CyberShadow CyberShadow left a 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,?

@dlang-bot dlang-bot merged commit f4c6d5c into dlang:master Aug 26, 2018
@ghost ghost deleted the issue-11431 branch August 27, 2018 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants