Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Shelljs.sort() changes the EOL '\r\n' (CRLF) into '\n' (LF) on a Windows PC #944
Comments
|
Most shelljs commands assume that, when outputting as a string, the user wants cross-platform-consistent newlines. We chose Maybe Happy to discuss better behavior here and to review a PR implementing the agreed-upon approach. This is low-priority and I will not work to fix this in the near future, so you should expect to write a PR yourself if you need this fixed. |
|
Your answer seems a bit awkward to me, especially the end of the first paragraph: "We chose Why not just check But, this is your decision, of course. |
|
I think I may not have been clear. We convert var output = shell.grep('foo', 'bar.txt');
// output might look like: "foo1\nfoo2\nfoo3\n"
// but dependent modules don't have to check for: "foo1\r\nfoo2\r\nfoo3\r\n"I think we should better advertise this behavior, and think we need the inverse operation for |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Node version (or tell us if you're using electron or some other framework):
Node v12.3.1
ShellJS version (the most recent version/Github branch you see the bug on):
shelljs@0.8.3
Operating system:
Microsoft Windows 10 Pro - v: 10.0.17763 Build 17763
Description of the bug:
Shelljs.sort() changes the EOL '\r\n' (CRLF) into '\n' (LF) on a Windows PC
Example ShellJS command to reproduce the error:
Create a file on a Windows PC containing the following text: 'xyz\r\nabc\r\n'. It has two lines of text each ending in the '\r\n' EOL
Let's call this file abc.txt.
Run the code shown below.
Examine the contents of the file, after sort, without overwriting it or changing in any way. If you inspect all characters you will find that, at least some of the EOL's will have changed. That is my conclusion after debugging a program I wrote.
On my system the file, after running the code below, would contain the string: 'abc\nxyz\r\n'
It's as if the last EOL is changed from CRLF to LF before sorting. That's strange behavior and causes problems, at least on a Windows system.