Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion patchwork/common/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def defered_temp_file(
return tempfile_fp


def open_with_chardet(file, mode="r", buffering=-1, errors=None, newline=None, closefd=True, opener=None):
def open_with_chardet(file, mode="r", buffering=-1, errors=None, newline="", closefd=True, opener=None):
detector = UniversalDetector()
with open(
file=file, mode="rb", buffering=buffering, errors=errors, newline=newline, closefd=closefd, opener=opener
Expand Down
4 changes: 2 additions & 2 deletions patchwork/steps/ModifyCode/ModifyCode.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

def save_file_contents(file_path, content):
"""Utility function to save content to a file."""
with open(file_path, "w") as file:
with open(file_path, "w", newline="") as file:
file.write(content)


Expand Down Expand Up @@ -45,7 +45,7 @@ def replace_code_in_file(

if path.exists() and start_line is not None and end_line is not None:
"""Replaces specified lines in a file with new code."""
text = path.read_text()
text = path.read_text(newline="")

lines = text.splitlines(keepends=True)

Expand Down
21 changes: 21 additions & 0 deletions reproduce_issue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
def read_and_write_file(filepath):
# Read the file and print original line endings
with open(filepath, 'rb') as f:
content = f.read()
print(f"Original line endings (hex):", content.hex())

# Read using current implementation approach
with open(filepath, 'r') as f:
content = f.read()

# Write back using current implementation approach
with open(filepath + '.modified', 'w') as f:
f.write(content)

# Read the modified file and print new line endings
with open(filepath + '.modified', 'rb') as f:
modified = f.read()
print(f"Modified line endings (hex):", modified.hex())

if __name__ == "__main__":
read_and_write_file('test_lineendings.py')
1 change: 1 addition & 0 deletions test_lineendings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def test_function():\r\n print('hello')\r\n return True\r\n
Loading