dependabot-nuget 0.308.0 → 0.309.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b510a9d8fdeba70a85b5eeab842a16642ec8e7beab71caa0e99f7e39bab6fd97
4
- data.tar.gz: c7ef1903b20b5eda9eb1e02153cedc3972a00c574e0acb4ad212cbaf16e673e4
3
+ metadata.gz: 77852ce632b0aebac74d328dc9b052115ac4dbe98aecb1db4e1cbc70b8fea2f6
4
+ data.tar.gz: 1a651c11a375578cc87717817d7c6d168abff9521c130f38e7a8caf098ba73a2
5
5
  SHA512:
6
- metadata.gz: '077584f16e3e95b98e69e74c67e3105dbf09455c19674bbc21929a91236fd5ba18b465f90103557e046ea867227bd6209e52d2faa958296234b020b0b24d09dc'
7
- data.tar.gz: b55391c84e09601c30a4046cf4b29263ea40f17360de2f70d7830978d7a8dca8994aec472bc92fcf5c813ceac235c003c0b449b3e08759d2e99f507c275df64e
6
+ metadata.gz: cd1387d4a376c66e6a22cfc498ac0ff17485a8d27e8644e6566fcd60478f52446614aa2563dc7bc0c07dfe2dc92f5604bc37cc5f66e5da2e0a457981443e4226
7
+ data.tar.gz: 230228595e7540a4de04d201b6d6cbd171ec73ef2259c20bd186d95652ed29477cebdced964ccecbde1bcdf481ce36819c0712f4ac8650b1595498931efdca00
@@ -3,6 +3,7 @@
3
3
  <PropertyGroup>
4
4
  <TargetFramework>$(CommonTargetFramework)</TargetFramework>
5
5
  <OutputType>Exe</OutputType>
6
+ <_NETFrameworkTargetingPacksVersion>[1.0.3]</_NETFrameworkTargetingPacksVersion>
6
7
  </PropertyGroup>
7
8
 
8
9
  <ItemGroup>
@@ -13,6 +14,24 @@
13
14
  <PackageReference Include="System.CommandLine" />
14
15
  </ItemGroup>
15
16
 
17
+ <ItemGroup Label="Targeting packs required for .NET Framework in SDK-style projects">
18
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies" Version="$(_NETFrameworkTargetingPacksVersion)" />
19
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net20" Version="$(_NETFrameworkTargetingPacksVersion)" />
20
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net35" Version="$(_NETFrameworkTargetingPacksVersion)" />
21
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net40" Version="$(_NETFrameworkTargetingPacksVersion)" />
22
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net45" Version="$(_NETFrameworkTargetingPacksVersion)" />
23
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net451" Version="$(_NETFrameworkTargetingPacksVersion)" />
24
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net452" Version="$(_NETFrameworkTargetingPacksVersion)" />
25
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net46" Version="$(_NETFrameworkTargetingPacksVersion)" />
26
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net461" Version="$(_NETFrameworkTargetingPacksVersion)" />
27
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net462" Version="$(_NETFrameworkTargetingPacksVersion)" />
28
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net47" Version="$(_NETFrameworkTargetingPacksVersion)" />
29
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net471" Version="$(_NETFrameworkTargetingPacksVersion)" />
30
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net472" Version="$(_NETFrameworkTargetingPacksVersion)" />
31
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net48" Version="$(_NETFrameworkTargetingPacksVersion)" />
32
+ <PackageDownload Include="Microsoft.NETFramework.ReferenceAssemblies.net481" Version="$(_NETFrameworkTargetingPacksVersion)" />
33
+ </ItemGroup>
34
+
16
35
  <ItemGroup>
17
36
  <InternalsVisibleTo Include="NuGetUpdater.Cli.Test"/>
18
37
  </ItemGroup>
@@ -1,4 +1,5 @@
1
1
  using System.CommandLine;
2
+ using System.Text;
2
3
 
3
4
  using NuGetUpdater.Cli.Commands;
4
5
 
@@ -8,6 +9,10 @@ internal sealed class Program
8
9
  {
9
10
  internal static async Task<int> Main(string[] args)
10
11
  {
12
+ // Allow loading of legacy code pages. This is useful for being able to load XML files with
13
+ // <?xml version="1.0" encoding="windows-1252"?>
14
+ Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
15
+
11
16
  var exitCode = 0;
12
17
  Action<int> setExitCode = code => exitCode = code;
13
18
 
@@ -652,6 +652,12 @@ internal static class SdkProjectDiscovery
652
652
  projectEvaluation = build.FindEvaluation(project.EvaluationId);
653
653
  }
654
654
 
655
+ if (!File.Exists(projectEvaluation?.ProjectFile))
656
+ {
657
+ // WPF creates temporary projects during evaluation that no longer exist on disk for analysis, but they're not necessary for our purposes.
658
+ return null;
659
+ }
660
+
655
661
  return projectEvaluation;
656
662
  }
657
663
 
@@ -125,6 +125,7 @@ public class RunWorker
125
125
  // TODO: pull out relevant dependencies, then check each for updates and track the changes
126
126
  var originalDependencyFileContents = new Dictionary<string, string>();
127
127
  var originalDependencyFileEOFs = new Dictionary<string, EOLType>();
128
+ var originalDependencyFileBOMs = new Dictionary<string, bool>();
128
129
  var actualUpdatedDependencies = new List<ReportedDependency>();
129
130
 
130
131
  // track original contents for later handling
@@ -133,8 +134,10 @@ public class RunWorker
133
134
  var repoFullPath = Path.Join(directory, fileName).FullyNormalizedRootedPath();
134
135
  var localFullPath = Path.Join(repoContentsPath.FullName, repoFullPath);
135
136
  var content = await File.ReadAllTextAsync(localFullPath);
137
+ var rawContent = await File.ReadAllBytesAsync(localFullPath);
136
138
  originalDependencyFileContents[repoFullPath] = content;
137
139
  originalDependencyFileEOFs[repoFullPath] = content.GetPredominantEOL();
140
+ originalDependencyFileBOMs[repoFullPath] = rawContent.HasBOM();
138
141
  }
139
142
 
140
143
  foreach (var project in discoveryResult.Projects)
@@ -257,15 +260,25 @@ public class RunWorker
257
260
  var updatedContent = await File.ReadAllTextAsync(localFullPath);
258
261
 
259
262
  updatedContent = updatedContent.SetEOL(originalDependencyFileEOFs[repoFullPath]);
260
- await File.WriteAllTextAsync(localFullPath, updatedContent);
263
+ var updatedRawContent = updatedContent.SetBOM(originalDependencyFileBOMs[repoFullPath]);
264
+ await File.WriteAllBytesAsync(localFullPath, updatedRawContent);
261
265
 
262
266
  if (updatedContent != originalContent)
263
267
  {
268
+ var reportedContent = updatedContent;
269
+ var encoding = "utf-8";
270
+ if (originalDependencyFileBOMs[repoFullPath])
271
+ {
272
+ reportedContent = Convert.ToBase64String(updatedRawContent);
273
+ encoding = "base64";
274
+ }
275
+
264
276
  updatedDependencyFiles[localFullPath] = new DependencyFile()
265
277
  {
266
278
  Name = Path.GetFileName(repoFullPath),
267
279
  Directory = Path.GetDirectoryName(repoFullPath)!.NormalizePathToUnix(),
268
- Content = updatedContent,
280
+ Content = reportedContent,
281
+ ContentEncoding = encoding,
269
282
  };
270
283
  }
271
284
  }
@@ -331,10 +344,17 @@ public class RunWorker
331
344
  Base64DependencyFiles = originalDependencyFileContents.OrderBy(kvp => kvp.Key).Select(kvp =>
332
345
  {
333
346
  var fullPath = kvp.Key.FullyNormalizedRootedPath();
347
+ var rawContent = Encoding.UTF8.GetBytes(kvp.Value);
348
+ if (originalDependencyFileBOMs[kvp.Key])
349
+ {
350
+ rawContent = Encoding.UTF8.GetPreamble().Concat(rawContent).ToArray();
351
+ }
352
+
334
353
  return new DependencyFile()
335
354
  {
336
355
  Name = Path.GetFileName(fullPath),
337
- Content = Convert.ToBase64String(Encoding.UTF8.GetBytes(kvp.Value)),
356
+ Content = Convert.ToBase64String(rawContent),
357
+ ContentEncoding = "base64",
338
358
  Directory = Path.GetDirectoryName(fullPath)!.NormalizePathToUnix(),
339
359
  };
340
360
  }).ToArray(),
@@ -1,3 +1,5 @@
1
+ using System.Collections.Immutable;
2
+
1
3
  using Microsoft.Language.Xml;
2
4
 
3
5
  namespace NuGetUpdater.Core.Updater
@@ -7,12 +9,19 @@ namespace NuGetUpdater.Core.Updater
7
9
  private readonly List<string?> _capturedConditions = new List<string?>();
8
10
  private readonly XmlFilePreAndPostProcessor _processor;
9
11
 
12
+ // These files only ship with a full Visual Studio install
10
13
  private readonly HashSet<string> ImportedFilesToIgnore = new(StringComparer.OrdinalIgnoreCase)
11
14
  {
12
15
  "Microsoft.TextTemplating.targets",
13
16
  "Microsoft.WebApplication.targets"
14
17
  };
15
18
 
19
+ // PackageReference elements with `GeneratePathProperty="true"` will cause a special property to be created.
20
+ private readonly ImmutableArray<string> PathSegmentsToIgnore =
21
+ [
22
+ "$(Pkg"
23
+ ];
24
+
16
25
  public SpecialImportsConditionPatcher(string projectFilePath)
17
26
  {
18
27
  _processor = new XmlFilePreAndPostProcessor(
@@ -25,8 +34,11 @@ namespace NuGetUpdater.Core.Updater
25
34
  var projectPath = e.GetAttributeValue("Project");
26
35
  if (projectPath is not null)
27
36
  {
28
- var projectFileName = Path.GetFileName(projectPath.NormalizePathToUnix());
29
- return ImportedFilesToIgnore.Contains(projectFileName);
37
+ var normalizedProjectPath = projectPath.NormalizePathToUnix();
38
+ var projectFileName = Path.GetFileName(normalizedProjectPath);
39
+ var hasForbiddenFile = ImportedFilesToIgnore.Contains(projectFileName);
40
+ var hasForbiddenPathSegment = PathSegmentsToIgnore.Any(p => normalizedProjectPath.Contains(p, StringComparison.OrdinalIgnoreCase));
41
+ return hasForbiddenFile || hasForbiddenPathSegment;
30
42
  }
31
43
 
32
44
  return false;
@@ -0,0 +1,35 @@
1
+ using System.Text;
2
+
3
+ namespace NuGetUpdater.Core.Utilities;
4
+
5
+ internal static class BOMHandling
6
+ {
7
+ public static bool HasBOM(this byte[] rawContent)
8
+ {
9
+ var bom = Encoding.UTF8.GetPreamble();
10
+ if (rawContent.Length >= bom.Length)
11
+ {
12
+ for (int i = 0; i < bom.Length; i++)
13
+ {
14
+ if (rawContent[i] != bom[i])
15
+ {
16
+ return false;
17
+ }
18
+ }
19
+
20
+ return true;
21
+ }
22
+
23
+ return false;
24
+ }
25
+ public static byte[] SetBOM(this string content, bool setBOM)
26
+ {
27
+ var rawContent = Encoding.UTF8.GetBytes(content);
28
+ if (setBOM)
29
+ {
30
+ rawContent = Encoding.UTF8.GetPreamble().Concat(rawContent).ToArray();
31
+ }
32
+
33
+ return rawContent;
34
+ }
35
+ }
@@ -19,6 +19,7 @@ namespace NuGetUpdater.Core.Test.Run;
19
19
  using static NuGetUpdater.Core.Utilities.EOLHandling;
20
20
 
21
21
  using TestFile = (string Path, string Content);
22
+ using RawTestFile = (string Path, byte[] Content);
22
23
 
23
24
  public class RunWorkerTests
24
25
  {
@@ -135,7 +136,8 @@ public class RunWorkerTests
135
136
  <PackageReference Include="Some.Package" Version="1.0.0" />
136
137
  </ItemGroup>
137
138
  </Project>
138
- """.SetEOL(EOL)))
139
+ """.SetEOL(EOL))),
140
+ ContentEncoding = "base64"
139
141
  }
140
142
  ],
141
143
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -359,7 +361,8 @@ public class RunWorkerTests
359
361
  <PackageReference Include="Some.Package;Some.Package2" Version="1.0.0" />
360
362
  </ItemGroup>
361
363
  </Project>
362
- """.SetEOL(EOL)))
364
+ """.SetEOL(EOL))),
365
+ ContentEncoding = "base64"
363
366
  }
364
367
  ],
365
368
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -732,7 +735,8 @@ public class RunWorkerTests
732
735
  <packages>
733
736
  <package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
734
737
  </packages>
735
- """.SetEOL(EOL)))
738
+ """.SetEOL(EOL))),
739
+ ContentEncoding = "base64"
736
740
  },
737
741
  new DependencyFile()
738
742
  {
@@ -747,7 +751,8 @@ public class RunWorkerTests
747
751
  <PackageReference Include="Some.Package" Version="1.0.0" />
748
752
  </ItemGroup>
749
753
  </Project>
750
- """.SetEOL(EOL)))
754
+ """.SetEOL(EOL))),
755
+ ContentEncoding = "base64"
751
756
  },
752
757
  ],
753
758
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -1152,7 +1157,8 @@ public class RunWorkerTests
1152
1157
  <packages>
1153
1158
  <package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
1154
1159
  </packages>
1155
- """.SetEOL(EOL)))
1160
+ """.SetEOL(EOL))),
1161
+ ContentEncoding = "base64"
1156
1162
  },
1157
1163
  new DependencyFile()
1158
1164
  {
@@ -1170,7 +1176,8 @@ public class RunWorkerTests
1170
1176
  <ProjectReference Include="../ProjectB/ProjectB.csproj" />
1171
1177
  </ItemGroup>
1172
1178
  </Project>
1173
- """.SetEOL(EOL)))
1179
+ """.SetEOL(EOL))),
1180
+ ContentEncoding = "base64"
1174
1181
  },
1175
1182
  new DependencyFile()
1176
1183
  {
@@ -1181,7 +1188,8 @@ public class RunWorkerTests
1181
1188
  <packages>
1182
1189
  <package id="Some.Package2" version="2.0.0" targetFramework="net8.0" />
1183
1190
  </packages>
1184
- """.SetEOL(EOL)))
1191
+ """.SetEOL(EOL))),
1192
+ ContentEncoding = "base64"
1185
1193
  },
1186
1194
  new DependencyFile()
1187
1195
  {
@@ -1196,7 +1204,8 @@ public class RunWorkerTests
1196
1204
  <PackageReference Include="Some.Package" Version="1.0.0" />
1197
1205
  </ItemGroup>
1198
1206
  </Project>
1199
- """.SetEOL(EOL)))
1207
+ """.SetEOL(EOL))),
1208
+ ContentEncoding = "base64"
1200
1209
  },
1201
1210
  ],
1202
1211
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -1625,7 +1634,8 @@ public class RunWorkerTests
1625
1634
  <SomePackageVersion>1.0.0</SomePackageVersion>
1626
1635
  </PropertyGroup>
1627
1636
  </Project>
1628
- """.SetEOL(EOL)))
1637
+ """.SetEOL(EOL))),
1638
+ ContentEncoding = "base64"
1629
1639
  },
1630
1640
  new DependencyFile()
1631
1641
  {
@@ -1640,7 +1650,8 @@ public class RunWorkerTests
1640
1650
  <PackageReference Include="Some.Package" Version="$(SomePackageVersion)" />
1641
1651
  </ItemGroup>
1642
1652
  </Project>
1643
- """.SetEOL(EOL)))
1653
+ """.SetEOL(EOL))),
1654
+ ContentEncoding = "base64"
1644
1655
  },
1645
1656
  new DependencyFile()
1646
1657
  {
@@ -1655,7 +1666,8 @@ public class RunWorkerTests
1655
1666
  <PackageReference Include="Some.Package" Version="$(SomePackageVersion)" />
1656
1667
  </ItemGroup>
1657
1668
  </Project>
1658
- """.SetEOL(EOL)))
1669
+ """.SetEOL(EOL))),
1670
+ ContentEncoding = "base64"
1659
1671
  },
1660
1672
  ],
1661
1673
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -1891,13 +1903,15 @@ public class RunWorkerTests
1891
1903
  {
1892
1904
  Directory = "/",
1893
1905
  Name = "Directory.Build.props",
1894
- Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("<Project />"))
1906
+ Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("<Project />")),
1907
+ ContentEncoding = "base64"
1895
1908
  },
1896
1909
  new DependencyFile()
1897
1910
  {
1898
1911
  Directory = "/",
1899
1912
  Name = "Directory.Build.targets",
1900
- Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("<Project />"))
1913
+ Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("<Project />")),
1914
+ ContentEncoding = "base64"
1901
1915
  },
1902
1916
  new DependencyFile()
1903
1917
  {
@@ -1909,7 +1923,8 @@ public class RunWorkerTests
1909
1923
  <ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
1910
1924
  </PropertyGroup>
1911
1925
  </Project>
1912
- """.SetEOL(EOL)))
1926
+ """.SetEOL(EOL))),
1927
+ ContentEncoding = "base64"
1913
1928
  },
1914
1929
  new DependencyFile()
1915
1930
  {
@@ -1924,7 +1939,8 @@ public class RunWorkerTests
1924
1939
  <PackageReference Include="Some.Package" Version="2.0.0" />
1925
1940
  </ItemGroup>
1926
1941
  </Project>
1927
- """.SetEOL(EOL)))
1942
+ """.SetEOL(EOL))),
1943
+ ContentEncoding = "base64"
1928
1944
  },
1929
1945
  new DependencyFile()
1930
1946
  {
@@ -1939,7 +1955,8 @@ public class RunWorkerTests
1939
1955
  <PackageReference Include="Some.Package" Version="1.0.0" />
1940
1956
  </ItemGroup>
1941
1957
  </Project>
1942
- """.SetEOL(EOL)))
1958
+ """.SetEOL(EOL))),
1959
+ ContentEncoding = "base64"
1943
1960
  },
1944
1961
  new DependencyFile()
1945
1962
  {
@@ -1954,7 +1971,8 @@ public class RunWorkerTests
1954
1971
  <PackageReference Include="Package.With.Transitive.Dependency" Version="0.1.0" />
1955
1972
  </ItemGroup>
1956
1973
  </Project>
1957
- """.SetEOL(EOL)))
1974
+ """.SetEOL(EOL))),
1975
+ ContentEncoding = "base64"
1958
1976
  }
1959
1977
  ],
1960
1978
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -2184,7 +2202,8 @@ public class RunWorkerTests
2184
2202
  {
2185
2203
  Directory = "/",
2186
2204
  Name = "project.csproj",
2187
- Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant"))
2205
+ Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant")),
2206
+ ContentEncoding = "base64"
2188
2207
  }
2189
2208
  ],
2190
2209
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -2273,7 +2292,8 @@ public class RunWorkerTests
2273
2292
  {
2274
2293
  Directory = "/",
2275
2294
  Name = "project.csproj",
2276
- Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant"))
2295
+ Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant")),
2296
+ ContentEncoding = "base64"
2277
2297
  }
2278
2298
  ],
2279
2299
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -2391,13 +2411,15 @@ public class RunWorkerTests
2391
2411
  {
2392
2412
  Directory = "/.config",
2393
2413
  Name = "dotnet-tools.json",
2394
- Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("dotnet-tools.json content old"))
2414
+ Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("dotnet-tools.json content old")),
2415
+ ContentEncoding = "base64"
2395
2416
  },
2396
2417
  new()
2397
2418
  {
2398
2419
  Directory = "/",
2399
2420
  Name = "global.json",
2400
- Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("global.json content old"))
2421
+ Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("global.json content old")),
2422
+ ContentEncoding = "base64"
2401
2423
  },
2402
2424
  ],
2403
2425
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -2598,7 +2620,8 @@ public class RunWorkerTests
2598
2620
  {
2599
2621
  Directory = "/",
2600
2622
  Name = "project.csproj",
2601
- Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant"))
2623
+ Content = Convert.ToBase64String(Encoding.UTF8.GetBytes("contents irrelevant")),
2624
+ ContentEncoding = "base64"
2602
2625
  }
2603
2626
  ],
2604
2627
  BaseCommitSha = "TEST-COMMIT-SHA",
@@ -2637,18 +2660,258 @@ public class RunWorkerTests
2637
2660
  );
2638
2661
  }
2639
2662
 
2640
- private static async Task RunAsync(Job job, TestFile[] files, IDiscoveryWorker? discoveryWorker, IAnalyzeWorker? analyzeWorker, IUpdaterWorker? updaterWorker, RunResult expectedResult, object[] expectedApiMessages, MockNuGetPackage[]? packages = null, ExperimentsManager? experimentsManager = null, string? repoContentsPath = null)
2663
+ [Fact]
2664
+ public async Task ByteOrderMarksAreDetectedAndRestored()
2665
+ {
2666
+ var rawBOM = Encoding.UTF8.GetPreamble();
2667
+
2668
+ // file1 goes from BOM to no BOM
2669
+ var file1ContentOriginal = rawBOM.Concat(Encoding.ASCII.GetBytes("content1")).ToArray();
2670
+ var file1ContentUpdated = Encoding.ASCII.GetBytes("updated1");
2671
+
2672
+ // file2 goes from no BOM to BOM
2673
+ var file2ContentOriginal = Encoding.ASCII.GetBytes("content2");
2674
+ var file2ContentUpdated = rawBOM.Concat(Encoding.ASCII.GetBytes("updated2")).ToArray();
2675
+
2676
+ await RunAsync(
2677
+ job: new Job()
2678
+ {
2679
+ Source = new()
2680
+ {
2681
+ Provider = "github",
2682
+ Repo = "test/repo",
2683
+ Directory = "/",
2684
+ }
2685
+ },
2686
+ rawFiles:
2687
+ [
2688
+ ("file1", file1ContentOriginal),
2689
+ ("file2", file2ContentOriginal)
2690
+ ],
2691
+ discoveryWorker: TestDiscoveryWorker.FromResults(("/", new()
2692
+ {
2693
+ Path = "/",
2694
+ Projects = [
2695
+ new()
2696
+ {
2697
+ FilePath = "file1",
2698
+ Dependencies = [new("Dependency1", "1.0.0", DependencyType.PackageReference)],
2699
+ ImportedFiles = [],
2700
+ AdditionalFiles = [],
2701
+ },
2702
+ new()
2703
+ {
2704
+ FilePath = "file2",
2705
+ Dependencies = [new("Dependency2", "2.0.0", DependencyType.PackageReference)],
2706
+ ImportedFiles = [],
2707
+ AdditionalFiles = [],
2708
+ }
2709
+ ]
2710
+ })),
2711
+ analyzeWorker: new TestAnalyzeWorker(args =>
2712
+ {
2713
+ AnalysisResult result = args.Item3.Name switch
2714
+ {
2715
+ "Dependency1" => new()
2716
+ {
2717
+ CanUpdate = true,
2718
+ UpdatedVersion = "1.0.1",
2719
+ UpdatedDependencies = [new("Dependency1", "1.0.1", DependencyType.PackageReference)],
2720
+ },
2721
+ "Dependency2" => new()
2722
+ {
2723
+ CanUpdate = true,
2724
+ UpdatedVersion = "2.0.1",
2725
+ UpdatedDependencies = [new("Dependency2", "2.0.1", DependencyType.PackageReference)],
2726
+ },
2727
+ _ => throw new NotImplementedException()
2728
+ };
2729
+ return Task.FromResult(result);
2730
+ }),
2731
+ updaterWorker: new TestUpdaterWorker(async args =>
2732
+ {
2733
+ var (repoRoot, filePath, dependencyName, _previousVersion, _newVersion, _isTransitive) = args;
2734
+
2735
+ // file1 is rewritten without BOM, file2 is rewritten with BOM
2736
+ var (updatedFileContent, newVersion) = dependencyName switch
2737
+ {
2738
+ "Dependency1" => (file1ContentUpdated, "1.0.1"),
2739
+ "Dependency2" => (file2ContentUpdated, "2.0.1"),
2740
+ _ => throw new NotImplementedException(),
2741
+ };
2742
+ var fullFilePath = Path.Join(repoRoot, filePath);
2743
+ await File.WriteAllBytesAsync(fullFilePath, updatedFileContent);
2744
+ return new UpdateOperationResult()
2745
+ {
2746
+ UpdateOperations = [new DirectUpdate()
2747
+ {
2748
+ DependencyName = dependencyName,
2749
+ NewVersion = NuGetVersion.Parse(newVersion),
2750
+ UpdatedFiles = [filePath],
2751
+ }],
2752
+ };
2753
+ }),
2754
+ expectedResult: new()
2755
+ {
2756
+ Base64DependencyFiles = [
2757
+ new()
2758
+ {
2759
+ Directory = "/",
2760
+ Name = "file1",
2761
+ Content = Convert.ToBase64String(file1ContentOriginal),
2762
+ ContentEncoding = "base64",
2763
+ },
2764
+ new()
2765
+ {
2766
+ Directory = "/",
2767
+ Name = "file2",
2768
+ Content = Convert.ToBase64String(file2ContentOriginal),
2769
+ ContentEncoding = "base64",
2770
+ }
2771
+ ],
2772
+ BaseCommitSha = "TEST-COMMIT-SHA",
2773
+ },
2774
+ expectedApiMessages: [
2775
+ new UpdatedDependencyList()
2776
+ {
2777
+ Dependencies = [
2778
+ new()
2779
+ {
2780
+ Name = "Dependency1",
2781
+ Version = "1.0.0",
2782
+ Requirements = [
2783
+ new()
2784
+ {
2785
+ Requirement = "1.0.0",
2786
+ File = "/file1",
2787
+ Groups = ["dependencies"],
2788
+ }
2789
+ ]
2790
+ },
2791
+ new()
2792
+ {
2793
+ Name = "Dependency2",
2794
+ Version = "2.0.0",
2795
+ Requirements = [
2796
+ new()
2797
+ {
2798
+ Requirement = "2.0.0",
2799
+ File = "/file2",
2800
+ Groups = ["dependencies"]
2801
+ }
2802
+ ]
2803
+ }
2804
+ ],
2805
+ DependencyFiles = ["/file1", "/file2"]
2806
+ },
2807
+ new IncrementMetric()
2808
+ {
2809
+ Metric = "updater.started",
2810
+ Tags = new()
2811
+ {
2812
+ ["operation"] = "group_update_all_versions"
2813
+ }
2814
+ },
2815
+ new CreatePullRequest()
2816
+ {
2817
+ Dependencies =
2818
+ [
2819
+ new ReportedDependency()
2820
+ {
2821
+ Name = "Dependency1",
2822
+ Version = "1.0.1",
2823
+ Requirements =
2824
+ [
2825
+ new ReportedRequirement()
2826
+ {
2827
+ Requirement = "1.0.1",
2828
+ File = "/file1",
2829
+ Groups = ["dependencies"],
2830
+ Source = new() { SourceUrl = null },
2831
+ }
2832
+ ],
2833
+ PreviousVersion = "1.0.0",
2834
+ PreviousRequirements =
2835
+ [
2836
+ new ReportedRequirement()
2837
+ {
2838
+ Requirement = "1.0.0",
2839
+ File = "/file1",
2840
+ Groups = ["dependencies"],
2841
+ }
2842
+ ],
2843
+ },
2844
+ new ReportedDependency()
2845
+ {
2846
+ Name = "Dependency2",
2847
+ Version = "2.0.1",
2848
+ Requirements =
2849
+ [
2850
+ new ReportedRequirement()
2851
+ {
2852
+ Requirement = "2.0.1",
2853
+ File = "/file2",
2854
+ Groups = ["dependencies"],
2855
+ Source = new() { SourceUrl = null },
2856
+ }
2857
+ ],
2858
+ PreviousVersion = "2.0.0",
2859
+ PreviousRequirements =
2860
+ [
2861
+ new ReportedRequirement()
2862
+ {
2863
+ Requirement = "2.0.0",
2864
+ File = "/file2",
2865
+ Groups = ["dependencies"],
2866
+ }
2867
+ ],
2868
+ },
2869
+ ],
2870
+ UpdatedDependencyFiles =
2871
+ [
2872
+ // original line endings have been restored
2873
+ new DependencyFile()
2874
+ {
2875
+ Name = "file1",
2876
+ Directory = "/",
2877
+ Content = Convert.ToBase64String(rawBOM.Concat(file1ContentUpdated).ToArray()),
2878
+ ContentEncoding = "base64",
2879
+ },
2880
+ new DependencyFile()
2881
+ {
2882
+ Name = "file2",
2883
+ Directory = "/",
2884
+ Content = "updated2",
2885
+ },
2886
+ ],
2887
+ BaseCommitSha = "TEST-COMMIT-SHA",
2888
+ CommitMessage = TestPullRequestCommitMessage,
2889
+ PrTitle = TestPullRequestTitle,
2890
+ PrBody = TestPullRequestBody,
2891
+ },
2892
+ new MarkAsProcessed("TEST-COMMIT-SHA"),
2893
+ ]
2894
+ );
2895
+ }
2896
+
2897
+ private static Task RunAsync(Job job, TestFile[] files, IDiscoveryWorker? discoveryWorker, IAnalyzeWorker? analyzeWorker, IUpdaterWorker? updaterWorker, RunResult expectedResult, object[] expectedApiMessages, MockNuGetPackage[]? packages = null, ExperimentsManager? experimentsManager = null, string? repoContentsPath = null)
2898
+ {
2899
+ var rawTestFiles = files.Select(f => (f.Path, Encoding.UTF8.GetBytes(f.Content))).ToArray();
2900
+ return RunAsync(job, rawTestFiles, discoveryWorker, analyzeWorker, updaterWorker, expectedResult, expectedApiMessages, packages, experimentsManager, repoContentsPath);
2901
+ }
2902
+
2903
+ private static async Task RunAsync(Job job, RawTestFile[] rawFiles, IDiscoveryWorker? discoveryWorker, IAnalyzeWorker? analyzeWorker, IUpdaterWorker? updaterWorker, RunResult expectedResult, object[] expectedApiMessages, MockNuGetPackage[]? packages = null, ExperimentsManager? experimentsManager = null, string? repoContentsPath = null)
2641
2904
  {
2642
2905
  // arrange
2643
2906
  using var tempDirectory = new TemporaryDirectory();
2644
2907
  repoContentsPath ??= tempDirectory.DirectoryPath;
2645
2908
  await UpdateWorkerTestBase.MockNuGetPackagesInDirectory(packages, repoContentsPath);
2646
- foreach (var (path, content) in files)
2909
+ foreach (var (path, content) in rawFiles)
2647
2910
  {
2648
2911
  var fullPath = Path.Combine(repoContentsPath, path);
2649
2912
  var directory = Path.GetDirectoryName(fullPath)!;
2650
2913
  Directory.CreateDirectory(directory);
2651
- await File.WriteAllTextAsync(fullPath, content);
2914
+ await File.WriteAllBytesAsync(fullPath, content);
2652
2915
  }
2653
2916
 
2654
2917
  // act
@@ -16,14 +16,13 @@ internal class TestDiscoveryWorker : IDiscoveryWorker
16
16
  return _getResult((repoRootPath, workspacePath));
17
17
  }
18
18
 
19
- public static TestDiscoveryWorker FromResults(params (string RepoRootPath, string WorkspacePath, WorkspaceDiscoveryResult Result)[] results)
19
+ public static TestDiscoveryWorker FromResults(params (string WorkspacePath, WorkspaceDiscoveryResult Result)[] results)
20
20
  {
21
- return new TestDiscoveryWorker(((string RepoRootPath, string WorkspacePath) input) =>
21
+ return new TestDiscoveryWorker(((string _RepoRootPath, string WorkspacePath) input) =>
22
22
  {
23
23
  foreach (var set in results)
24
24
  {
25
- if (set.RepoRootPath == input.RepoRootPath &&
26
- set.WorkspacePath == input.WorkspacePath)
25
+ if (set.WorkspacePath == input.WorkspacePath)
27
26
  {
28
27
  return Task.FromResult(set.Result);
29
28
  }
@@ -31,6 +31,8 @@ public class SpecialFilePatcherTests
31
31
 
32
32
  public static IEnumerable<object[]> SpecialImportsConditionPatcherTestData()
33
33
  {
34
+ // magic file names
35
+
34
36
  // one-off test to verify namespaces don't interfere
35
37
  yield return
36
38
  [
@@ -95,5 +97,22 @@ public class SpecialFilePatcherTests
95
97
  </Project>
96
98
  """
97
99
  ];
100
+
101
+ // magic property segments
102
+ yield return
103
+ [
104
+ // fileContent
105
+ """
106
+ <Project>
107
+ <Import Project="$(PkgSome_Package)\build\Some.Package.targets" />
108
+ </Project>
109
+ """,
110
+ // expectedPatchedContent
111
+ """
112
+ <Project>
113
+ <Import Project="$(PkgSome_Package)\build\Some.Package.targets" Condition="false" />
114
+ </Project>
115
+ """
116
+ ];
98
117
  }
99
118
  }
@@ -0,0 +1,66 @@
1
+ using NuGetUpdater.Core.Utilities;
2
+
3
+ using Xunit;
4
+
5
+ namespace NuGetUpdater.Core.Test.Utilities;
6
+
7
+ public class BOMHandlingTests
8
+ {
9
+ [Theory]
10
+ [MemberData(nameof(HasBOMTestData))]
11
+ public void HasBOM(byte[] content, bool expectedHasBOM)
12
+ {
13
+ var actualHasBOM = content.HasBOM();
14
+ Assert.Equal(expectedHasBOM, actualHasBOM);
15
+ }
16
+
17
+ [Theory]
18
+ [MemberData(nameof(SetBOMTestData))]
19
+ public void SetBOM(string content, bool setBOM, byte[] expectedBytes)
20
+ {
21
+ var actualBytes = content.SetBOM(setBOM);
22
+ AssertEx.Equal(expectedBytes, actualBytes);
23
+ }
24
+
25
+ public static IEnumerable<object[]> HasBOMTestData()
26
+ {
27
+ yield return
28
+ [
29
+ // content
30
+ new byte[] { 0xEF, 0xBB, 0xBF, (byte)'A' },
31
+ // expectedHasBOM
32
+ true
33
+ ];
34
+
35
+ yield return
36
+ [
37
+ // content
38
+ new byte[] { (byte)'A' },
39
+ // expectedHasBOM
40
+ false
41
+ ];
42
+ }
43
+
44
+ public static IEnumerable<object[]> SetBOMTestData()
45
+ {
46
+ yield return
47
+ [
48
+ // content
49
+ "A",
50
+ // setBOM
51
+ true,
52
+ // expectedBytes
53
+ new byte[] { 0xEF, 0xBB, 0xBF, (byte)'A' }
54
+ ];
55
+
56
+ yield return
57
+ [
58
+ // content
59
+ "A",
60
+ // setBOM
61
+ false,
62
+ // expectedBytes
63
+ new byte[] { (byte)'A' }
64
+ ];
65
+ }
66
+ }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-nuget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.308.0
4
+ version: 0.309.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-12 00:00:00.000000000 Z
10
+ date: 2025-04-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: dependabot-common
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.308.0
18
+ version: 0.309.0
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.308.0
25
+ version: 0.309.0
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rubyzip
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -378,6 +378,7 @@ files:
378
378
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackageReference.cs
379
379
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Update/UpdateWorkerTests.PackagesConfig.cs
380
380
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/AssertEx.cs
381
+ - helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/BOMHandlingTests.cs
381
382
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/DiffUtil.cs
382
383
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/EOLHandlingTests.cs
383
384
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Utilities/JsonHelperTests.cs
@@ -503,6 +504,7 @@ files:
503
504
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdateResult.cs
504
505
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/UpdaterWorker.cs
505
506
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Updater/XmlFilePreAndPostProcessor.cs
507
+ - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/BOMHandling.cs
506
508
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/CollectionExtensions.cs
507
509
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/ConsoleLogger.cs
508
510
  - helpers/lib/NuGetUpdater/NuGetUpdater.Core/Utilities/DependencyConflictResolver.cs
@@ -551,7 +553,7 @@ licenses:
551
553
  - MIT
552
554
  metadata:
553
555
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
554
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.308.0
556
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.309.0
555
557
  rdoc_options: []
556
558
  require_paths:
557
559
  - lib