Skip to content

Commit 8e57335

Browse files
aaronpowellCopilotCopilot
authored
fix: handle multi-line XML comments in PackageDiffAsync (#1422)
* fix: handle multi-line XML comments in PackageDiffAsync Add an inComment flag to correctly track multi-line XML comment blocks in Directory.Packages.props diffs. Previously, continuation lines of a block comment did not start with '<!--', causing uncertain = true and triggering a full test matrix run unnecessarily. Changes: - Track inComment state across lines - Skip continuation lines until '-->' is found - Handle comments that follow content on the same line - Guard the final uncertain = true with a non-empty line check Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent bf90b41 commit 8e57335

1 file changed

Lines changed: 47 additions & 2 deletions

File tree

eng/testing/select-affected-tests.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ private static async Task<List<string>> ChangedFilesAsync(string repoRoot, strin
679679

680680
var packageIds = new HashSet<string>(StringComparer.Ordinal);
681681
var uncertain = false;
682+
var inComment = false;
682683

683684
foreach (var rawLine in output.Split('\n', StringSplitOptions.TrimEntries))
684685
{
@@ -698,19 +699,63 @@ private static async Task<List<string>> ChangedFilesAsync(string repoRoot, strin
698699
}
699700

700701
var line = rawLine[1..].Trim();
701-
if (string.IsNullOrEmpty(line) || line.StartsWith("<!--", StringComparison.Ordinal))
702+
if (string.IsNullOrEmpty(line))
702703
{
703704
continue;
704705
}
705706

707+
// Track multi-line XML comment state so that continuation lines
708+
// of a block comment don't incorrectly trigger uncertain = true.
709+
if (inComment)
710+
{
711+
var commentEnd = line.IndexOf("-->", StringComparison.Ordinal);
712+
if (commentEnd >= 0)
713+
{
714+
inComment = false;
715+
716+
// Process any content after the comment close marker on the same line.
717+
line = line[(commentEnd + 3)..].Trim();
718+
if (string.IsNullOrEmpty(line))
719+
{
720+
continue;
721+
}
722+
}
723+
else
724+
{
725+
continue;
726+
}
727+
}
728+
729+
var commentStart = line.IndexOf("<!--", StringComparison.Ordinal);
730+
if (commentStart >= 0)
731+
{
732+
// If the comment doesn't close on this line, enter multi-line comment mode.
733+
if (line.IndexOf("-->", commentStart + 4, StringComparison.Ordinal) < 0)
734+
{
735+
inComment = true;
736+
}
737+
738+
if (commentStart == 0)
739+
{
740+
// Entire line is a comment — skip it.
741+
continue;
742+
}
743+
744+
// Content precedes the comment; trim off the comment (and anything after it) before further processing.
745+
line = line[..commentStart].Trim();
746+
}
747+
706748
if (line.Contains("PackageVersion", StringComparison.Ordinal) &&
707749
TryGetAttributeValue(line, "Include", out var include))
708750
{
709751
packageIds.Add(include);
710752
continue;
711753
}
712754

713-
uncertain = true;
755+
if (!string.IsNullOrEmpty(line))
756+
{
757+
uncertain = true;
758+
}
714759
}
715760

716761
return (packageIds, uncertain);

0 commit comments

Comments
 (0)