Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/Fallout.Migrate/Steps/RewriteCsprojsStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal sealed class RewriteCsprojsStep : IMigrationStep
// (ADR-0010), so a migrated project must not carry a dead <FalloutTelemetryVersion>.
// Matches the whole element line (either legacy Nuke* or already-Fallout* spelling).
private static readonly Regex telemetryVersionPropertyPattern = new(
@"^[ \t]*<(?<tag>(?:Nuke|Fallout)TelemetryVersion)>.*?</\k<tag>>\s*\r?\n?",
@"^[ \t]*<(?<tag>(?:Nuke|Fallout)TelemetryVersion)>.*?</\k<tag>>[ \t]*\r?\n?",
RegexOptions.Compiled | RegexOptions.Multiline);

// Strip explicit `System.Security.Cryptography.Xml` PackageReferences. NUKE-era projects
Expand All @@ -55,7 +55,7 @@ internal sealed class RewriteCsprojsStep : IMigrationStep
// migrated project wants (#217). Matches a self-closing element with optional surrounding
// indentation + trailing newline.
private static readonly Regex cryptographyXmlPackageRefPattern = new(
@"^[ \t]*<PackageReference\s+Include=""System\.Security\.Cryptography\.Xml""[^/]*/>\s*\r?\n?",
@"^[ \t]*<PackageReference\s+Include=""System\.Security\.Cryptography\.Xml""[^/]*/>[ \t]*\r?\n?",
RegexOptions.Compiled | RegexOptions.Multiline);

/// <inheritdoc />
Expand Down
55 changes: 55 additions & 0 deletions tests/Fallout.Migrate.Specs/RewriteCsprojsStepSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public async Task Unrelated_nuke_prefixed_properties_are_left_alone()
</PropertyGroup>
</Project>
""";

(tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);
Expand All @@ -123,6 +124,7 @@ public async Task Content_without_nuke_references_is_returned_unchanged()
</PropertyGroup>
</Project>
""";

(tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);
Expand Down Expand Up @@ -232,6 +234,7 @@ public async Task Other_system_packages_are_left_alone()
</ItemGroup>
</Project>
""";

(tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);
Expand All @@ -240,4 +243,56 @@ public async Task Other_system_packages_are_left_alone()
var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();
buildCsproj.Should().Be(input);
}

[Fact]
public async Task Telemetry_remove_pattern_does_not_act_greedy()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<FalloutTelemetryVersion>1</FalloutTelemetryVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
""";

(tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();
buildCsproj.Should().Be("""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<IsPackable>false</IsPackable>
</PropertyGroup>
</Project>
""");
}

[Fact]
public async Task Cryptography_package_pin_remove_pattern_does_not_act_greedy()
{
const string input = """
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Fallout.Common" Version="10.3.49" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="10.0.10" />
</ItemGroup>
</Project>
""";

(tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false);

await new RewriteCsprojsStep().ExecuteAsync(context, summary);

var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText();
buildCsproj.Should().Be("""
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<PackageReference Include="Fallout.Common" Version="10.3.49" />
</ItemGroup>
</Project>
""");
}
}
Loading