diff --git a/src/Fallout.Migrate/Steps/RewriteCsprojsStep.cs b/src/Fallout.Migrate/Steps/RewriteCsprojsStep.cs index 1d211826..3114c6d1 100644 --- a/src/Fallout.Migrate/Steps/RewriteCsprojsStep.cs +++ b/src/Fallout.Migrate/Steps/RewriteCsprojsStep.cs @@ -45,7 +45,7 @@ internal sealed class RewriteCsprojsStep : IMigrationStep // (ADR-0010), so a migrated project must not carry a dead . // Matches the whole element line (either legacy Nuke* or already-Fallout* spelling). private static readonly Regex telemetryVersionPropertyPattern = new( - @"^[ \t]*<(?(?:Nuke|Fallout)TelemetryVersion)>.*?>\s*\r?\n?", + @"^[ \t]*<(?(?:Nuke|Fallout)TelemetryVersion)>.*?>[ \t]*\r?\n?", RegexOptions.Compiled | RegexOptions.Multiline); // Strip explicit `System.Security.Cryptography.Xml` PackageReferences. NUKE-era projects @@ -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]*\s*\r?\n?", + @"^[ \t]*[ \t]*\r?\n?", RegexOptions.Compiled | RegexOptions.Multiline); /// diff --git a/tests/Fallout.Migrate.Specs/RewriteCsprojsStepSpecs.cs b/tests/Fallout.Migrate.Specs/RewriteCsprojsStepSpecs.cs index 4686d5b4..0502b417 100644 --- a/tests/Fallout.Migrate.Specs/RewriteCsprojsStepSpecs.cs +++ b/tests/Fallout.Migrate.Specs/RewriteCsprojsStepSpecs.cs @@ -104,6 +104,7 @@ public async Task Unrelated_nuke_prefixed_properties_are_left_alone() """; + (tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false); await new RewriteCsprojsStep().ExecuteAsync(context, summary); @@ -123,6 +124,7 @@ public async Task Content_without_nuke_references_is_returned_unchanged() """; + (tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false); await new RewriteCsprojsStep().ExecuteAsync(context, summary); @@ -232,6 +234,7 @@ public async Task Other_system_packages_are_left_alone() """; + (tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false); await new RewriteCsprojsStep().ExecuteAsync(context, summary); @@ -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 = """ + + + 1 + false + + + """; + + (tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false); + + await new RewriteCsprojsStep().ExecuteAsync(context, summary); + + var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText(); + buildCsproj.Should().Be(""" + + + false + + + """); + } + + [Fact] + public async Task Cryptography_package_pin_remove_pattern_does_not_act_greedy() + { + const string input = """ + + + + + + + """; + + (tempDirectory / "build" / "_build.csproj").WriteAllText(input, eofLineBreak: false); + + await new RewriteCsprojsStep().ExecuteAsync(context, summary); + + var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText(); + buildCsproj.Should().Be(""" + + + + + + """); + } }