{"action":"created","issue":{"url":"https://api.github.com/repos/pre-commit/pre-commit-hooks/issues/134","repository_url":"https://api.github.com/repos/pre-commit/pre-commit-hooks","labels_url":"https://api.github.com/repos/pre-commit/pre-commit-hooks/issues/134/labels{/name}","comments_url":"https://api.github.com/repos/pre-commit/pre-commit-hooks/issues/134/comments","events_url":"https://api.github.com/repos/pre-commit/pre-commit-hooks/issues/134/events","html_url":"https://github.com/pre-commit/pre-commit-hooks/issues/134","id":171906258,"number":134,"title":"Non-utf8 file will cause trailing-whitespace to truncate the file contents","user":{"login":"Lucas-C","id":925560,"avatar_url":"https://avatars.githubusercontent.com/u/925560?v=3","gravatar_id":"","url":"https://api.github.com/users/Lucas-C","html_url":"https://github.com/Lucas-C","followers_url":"https://api.github.com/users/Lucas-C/followers","following_url":"https://api.github.com/users/Lucas-C/following{/other_user}","gists_url":"https://api.github.com/users/Lucas-C/gists{/gist_id}","starred_url":"https://api.github.com/users/Lucas-C/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lucas-C/subscriptions","organizations_url":"https://api.github.com/users/Lucas-C/orgs","repos_url":"https://api.github.com/users/Lucas-C/repos","events_url":"https://api.github.com/users/Lucas-C/events{/privacy}","received_events_url":"https://api.github.com/users/Lucas-C/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pre-commit/pre-commit-hooks/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-08-18T13:52:39Z","updated_at":"2016-08-18T16:23:27Z","closed_at":null,"body":"Hi,\r\n\r\n(I started investigating this in https://github.com/pre-commit/pre-commit/issues/397)\r\n\r\nBug reproductions steps, after setting up a git repository with the \"trailing-whitespace\" pre-commit hook installed (with the latest sha: 775a7906cd6004bec2401a85ed16d5b3540d2f94):\r\n```\r\necho -en '\\x3c\\x61\\x3e\\xe9\\x20\\x0a\\x3c\\x2f\\x61\\x3e' > minimal_crasher.xml\r\ngit add minimal_crasher.xml\r\npre-commit run trailing-whitespace --files minimal_crasher.xml\r\n```\r\n\r\nResults in:\r\n````\r\nTrim Trailing Whitespace...............................................................................................................................................................Failed\r\nhookid: trailing-whitespace\r\n\r\nFiles were modified by this hook. Additional output:\r\n\r\nFixing minimal_crasher.xml\r\nTraceback (most recent call last):\r\n  File \"/home/lucas_cimon/.pre-commit/repok3wjweh4/py_env-default/bin/trailing-whitespace-fixer\", line 9, in <module>\r\n    load_entry_point('pre-commit-hooks==0.6.0', 'console_scripts', 'trailing-whitespace-fixer')()\r\n  File \"/home/lucas_cimon/.pre-commit/repok3wjweh4/py_env-default/lib/python3.4/site-packages/pre_commit_hooks/trailing_whitespace_fixer.py\", line 71, in fix_trailing_whitespace\r\n    _fix_file(bad_whitespace_file, all_markdown or extension in md_exts)\r\n  File \"/home/lucas_cimon/.pre-commit/repok3wjweh4/py_env-default/lib/python3.4/site-packages/pre_commit_hooks/trailing_whitespace_fixer.py\", line 12, in _fix_file\r\n    for line in fileinput.input([filename], inplace=True):\r\n  File \"/usr/lib/python3.4/fileinput.py\", line 263, in __next__\r\n    line = self.readline()\r\n  File \"/usr/lib/python3.4/fileinput.py\", line 363, in readline\r\n    self._buffer = self._file.readlines(self._bufsize)\r\n  File \"/home/lucas_cimon/.pre-commit/repok3wjweh4/py_env-default/lib/python3.4/codecs.py\", line 319, in decode\r\n    (result, consumed) = self._buffer_decode(data, self.errors, final)\r\nUnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 3: invalid continuation byte\r\n```\r\n\r\nAnd **all the content of `minimal_crasher.xml` lost** !!\r\n\r\nIn this test the xml file is very small, but it can happen with any file size nor number of staged modifications !\r\n"},"comment":{"url":"https://api.github.com/repos/pre-commit/pre-commit-hooks/issues/comments/240777501","html_url":"https://github.com/pre-commit/pre-commit-hooks/issues/134#issuecomment-240777501","issue_url":"https://api.github.com/repos/pre-commit/pre-commit-hooks/issues/134","id":240777501,"user":{"login":"Lucas-C","id":925560,"avatar_url":"https://avatars.githubusercontent.com/u/925560?v=3","gravatar_id":"","url":"https://api.github.com/users/Lucas-C","html_url":"https://github.com/Lucas-C","followers_url":"https://api.github.com/users/Lucas-C/followers","following_url":"https://api.github.com/users/Lucas-C/following{/other_user}","gists_url":"https://api.github.com/users/Lucas-C/gists{/gist_id}","starred_url":"https://api.github.com/users/Lucas-C/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Lucas-C/subscriptions","organizations_url":"https://api.github.com/users/Lucas-C/orgs","repos_url":"https://api.github.com/users/Lucas-C/repos","events_url":"https://api.github.com/users/Lucas-C/events{/privacy}","received_events_url":"https://api.github.com/users/Lucas-C/received_events","type":"User","site_admin":false},"created_at":"2016-08-18T16:23:27Z","updated_at":"2016-08-18T16:23:27Z","body":"Ok.\r\nI'm going to do this tomorrow, and I'll wait for the 1st PR to get tour approval."}}
{"actor":{"display_login":"Lucas-C"}}