{"action":"opened","issue":{"url":"https://api.github.com/repos/timothycrosley/isort/issues/671","repository_url":"https://api.github.com/repos/timothycrosley/isort","labels_url":"https://api.github.com/repos/timothycrosley/isort/issues/671/labels{/name}","comments_url":"https://api.github.com/repos/timothycrosley/isort/issues/671/comments","events_url":"https://api.github.com/repos/timothycrosley/isort/issues/671/events","html_url":"https://github.com/timothycrosley/isort/issues/671","id":296168170,"number":671,"title":"isort is corrupting CRLF files","user":{"login":"jchv","id":938744,"avatar_url":"https://avatars1.githubusercontent.com/u/938744?v=4","gravatar_id":"","url":"https://api.github.com/users/jchv","html_url":"https://github.com/jchv","followers_url":"https://api.github.com/users/jchv/followers","following_url":"https://api.github.com/users/jchv/following{/other_user}","gists_url":"https://api.github.com/users/jchv/gists{/gist_id}","starred_url":"https://api.github.com/users/jchv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jchv/subscriptions","organizations_url":"https://api.github.com/users/jchv/orgs","repos_url":"https://api.github.com/users/jchv/repos","events_url":"https://api.github.com/users/jchv/events{/privacy}","received_events_url":"https://api.github.com/users/jchv/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-11T07:18:26Z","updated_at":"2018-02-11T07:18:26Z","closed_at":null,"author_association":"NONE","body":"With Python 3.6.3 and isort 4.3.3, my CRLF files are being corrupted. Every line ends with CR CR LF instead of CR LF; a lot of software treats this sequence differently, but it usually manifests as either two line endings or one line ending and an excess CR. Needless to say, this is painful once it occurs, leaving a lot of a codebase damaged. :)\r\n\r\nThe problem is really obvious now that I look, so I'll submit a PR. Basically:\r\n\r\n**1.** CRLF is applied upon joining the lines.\r\n```python\r\n        self.output = self.line_separator.join(self.out_lines)\r\n```\r\n\r\n**2.** CRLF is applied again upon saving the file. The `newline` argument seems to blindly replace all instances of `\\n` with whatever you stick in it, even though the lines already end in `\\r\\n`.\r\n```python\r\n            with io.open(self.file_path, encoding=self.file_encoding, mode='w', newline=self.line_separator) as output_file:\r\n                print(\"Fixing {0}\".format(self.file_path))\r\n                output_file.write(self.output)\r\n```\r\n\r\nKind of off-topic: anyone have any idea why this is broken now? It seems really unlikely to me that it literally never worked, and yet since the PR that was supposed to fix line endings, it doesn't seem the code has changed dramatically. My best guess is that Python's behavior for `newline` used to have heuristics to prevent this, but that seems asinine..."}}
{"actor":{"display_login":"jchv"}}