Skip to content
Merged
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
6 changes: 2 additions & 4 deletions eng/common/SetupNugetSources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,8 @@ EnableInternalPackageSource() {
grep -i "<add key=\"$PackageSourceName\" value=\"true\"" "$ConfigFile" > /dev/null
if [ "$?" == "0" ]; then
echo "Enabling internal source '$PackageSourceName'."
# Remove the disabled entry
local OldDisableValue="<add key=\"$PackageSourceName\" value=\"true\" />"
local NewDisableValue="<!-- Reenabled for build : $PackageSourceName -->"
sed -i.bak "s|$OldDisableValue|$NewDisableValue|" "$ConfigFile"
# Remove the disabled entry (including any surrounding comments or whitespace on the same line)
sed -i.bak "/<add key=\"$PackageSourceName\" value=\"true\" \/>/d" "$ConfigFile"

# Add the source name to PackageSources for credential handling
PackageSources+=("$PackageSourceName")
Expand Down
35 changes: 35 additions & 0 deletions src/Microsoft.DotNet.SetupNugetSources.Tests/FeedEnablingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,40 @@ public async Task ConfigWithNoDisabledSources_StillAddsInternalFeeds()
"https://pkgs.dev.azure.com/dnceng/internal/_packaging/dotnet6-internal-transport/nuget/v3/index.json",
"should add dotnet6-internal-transport feed");
}

[Fact]
public async Task ConfigWithCommentedOutDisabledDarcIntFeeds_RemovesEntriesAndProducesValidXml()
{
// Arrange - this test covers the issue where commented-out disabled entries would create invalid XML
var originalConfig = @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<packageSources>
<add key=""dotnet-public"" value=""https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json"" />
<add key=""darc-int-dotnet-roslyn-12345"" value=""https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-roslyn-12345/nuget/v3/index.json"" />
</packageSources>
<disabledPackageSources>
<!-- <add key=""darc-int-dotnet-roslyn-12345"" value=""true"" /> -->
</disabledPackageSources>
</configuration>";
var configPath = Path.Combine(_testOutputDirectory, "nuget.config");
await Task.Run(() => File.WriteAllText(configPath, originalConfig));

// Act
var result = await _scriptRunner.RunScript(configPath);

// Assert
result.exitCode.Should().Be(0, "Script should succeed, but got error: {result.error}");
var modifiedConfig = await Task.Run(() => File.ReadAllText(configPath));

// The modified config should be valid XML (this would fail if nested comments were created)
Action parseXml = () => System.Xml.Linq.XDocument.Parse(modifiedConfig);
parseXml.Should().NotThrow("modified config should be valid XML without nested comments");

// The darc-int feed should not be disabled
modifiedConfig.ShouldNotBeDisabled("darc-int-dotnet-roslyn-12345", "darc-int feed should be enabled");

// The commented-out line should be removed entirely (no comment remnants)
modifiedConfig.Should().NotContain("Reenabled for build", "should not add comments when removing disabled entries");
}
}
}
Loading