Skip to content

Commit

Permalink
Fix Dependabot::Nuget::FileUpdater file content normalization (line-e…
Browse files Browse the repository at this point in the history
…ndings)
  • Loading branch information
nklyshko authored and kbukum1 committed Jun 28, 2024
1 parent 876f840 commit 44b597b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions nuget/lib/dependabot/nuget/file_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,15 @@ def dotnet_tools_json_dependencies
sig { params(dependency_file: Dependabot::DependencyFile, updated_content: String).returns(String) }
def normalize_content(dependency_file, updated_content)
# Fix up line endings
if dependency_file.content&.include?("\r\n") && updated_content.match?(/(?<!\r)\n/)
if dependency_file.content&.include?("\r\n")
# The original content contain windows style newlines.
# Ensure the updated content also uses windows style newlines.
updated_content = updated_content.gsub(/(?<!\r)\n/, "\r\n")
puts "Fixing mismatched Windows line endings for [#{dependency_file.name}]."
if updated_content.match?(/(?<!\r)\n/)
# Ensure the updated content also uses windows style newlines.
updated_content = updated_content.gsub(/(?<!\r)\n/, "\r\n")
puts "Fixing mismatched Windows line endings for [#{dependency_file.name}]."
end
elsif updated_content.include?("\r\n")
# The original content does not contain windows style newlines.
# The original content does not contain windows style newlines, but the updated content does.
# Ensure the updated content uses unix style newlines.
updated_content = updated_content.gsub("\r\n", "\n")
puts "Fixing mismatched Unix line endings for [#{dependency_file.name}]."
Expand Down

0 comments on commit 44b597b

Please sign in to comment.