Skip to content

Commit cd69ef9

Browse files
Preserve original line ending style in lockfile metadata replacement
Address code review feedback: detect and preserve the original line ending style (CRLF or LF) when replacing python-versions in lockfile metadata, instead of hardcoding LF. Co-authored-by: AbhishekBhaskar <22154418+AbhishekBhaskar@users.noreply.github.com>
1 parent 54116af commit cd69ef9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

python/lib/dependabot/python/file_updater/poetry_file_updater.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ def updated_lockfile_content
143143
original_locked_python = TomlRB.parse(T.must(lockfile).content)["metadata"]["python-versions"]
144144

145145
new_lockfile.gsub!(/\[metadata\](?:\r?\n).*python-versions[^\r\n]+(?:\r?\n)/m) do |match|
146-
match.gsub(/(["']).*(['"])(?:\r?\n)\Z/, '\1' + original_locked_python + '\1' + "\n")
146+
# Detect the line ending style from the match (CRLF or LF)
147+
line_ending = match.include?("\r\n") ? "\r\n" : "\n"
148+
match.gsub(/(["']).*(['"])(?:\r?\n)\Z/, '\1' + original_locked_python + '\1' + line_ending)
147149
end
148150

149151
tmp_hash =

0 commit comments

Comments
 (0)