Incorporate patch to support isolated CR
diff --git a/pre_commit_hooks/end_of_file_fixer.py b/pre_commit_hooks/end_of_file_fixer.py
index 37ebbb5..5ab1b7b 100644
--- a/pre_commit_hooks/end_of_file_fixer.py
+++ b/pre_commit_hooks/end_of_file_fixer.py
@@ -15,13 +15,13 @@
return 0
last_character = file_obj.read(1)
# last_character will be '' for an empty file
- if last_character != b'\n' and last_character != b'':
+ if last_character not in {b'\n', b'\r'} and last_character != b'':
# Needs this seek for windows, otherwise IOError
file_obj.seek(0, os.SEEK_END)
file_obj.write(b'\n')
return 1
- while last_character == b'\n' or last_character == b'\r':
+ while last_character in {b'\n', b'\r'}:
# Deal with the beginning of the file
if file_obj.tell() == 1:
# If we've reached the beginning of the file and it is all
@@ -38,8 +38,10 @@
# newlines. If we find extraneous newlines, then backtrack and trim them.
position = file_obj.tell()
remaining = file_obj.read()
- for sequence in [b'\n', b'\r\n']:
- if remaining.startswith(sequence) and len(remaining) > len(sequence):
+ for sequence in (b'\n', b'\r\n', b'\r'):
+ if remaining == sequence:
+ return 0
+ elif remaining.startswith(sequence):
file_obj.seek(position + len(sequence))
file_obj.truncate()
return 1