Skip to content

Commit

Permalink
(NuGet#9) Return null for configuration elements
Browse files Browse the repository at this point in the history
This prevents any configuration from nuget.config files being returned to
prevent NuGet configuration from tainting Chocolatey
  • Loading branch information
TheCakeIsNaOH committed Jan 10, 2023
1 parent a0210f0 commit 9bca314
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/NuGet.Core/NuGet.Configuration/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ public class Settings : ISettings

public SettingSection GetSection(string sectionName)
{
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CHOCOLATEY_VERSION")))
{
return null;
}
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

if (_computedSections.TryGetValue(sectionName, out var section))
{
return section.Clone() as SettingSection;
Expand Down
23 changes: 23 additions & 0 deletions src/NuGet.Core/NuGet.Configuration/Settings/SettingsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ public SettingsFile(string directoryPath, string fileName, bool isMachineWide, b
/// <returns>null if no section with the given name was found</returns>
public SettingSection GetSection(string sectionName)
{
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CHOCOLATEY_VERSION")))
{
return null;
}
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

return _rootElement.GetSection(sectionName);
}

Expand Down Expand Up @@ -194,6 +205,18 @@ internal void SaveToDisk()
/// </remarks>
internal bool TryGetSection(string sectionName, out SettingSection section)
{
//////////////////////////////////////////////////////////
// Start - Chocolatey Specific Modification
//////////////////////////////////////////////////////////
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CHOCOLATEY_VERSION")))
{
section = null;
return false;
}
//////////////////////////////////////////////////////////
// End - Chocolatey Specific Modification
//////////////////////////////////////////////////////////

return _rootElement.Sections.TryGetValue(sectionName, out section);
}

Expand Down

0 comments on commit 9bca314

Please sign in to comment.