Skip to content

Commit

Permalink
(#502) Fix path separator in nuspec file element
Browse files Browse the repository at this point in the history
Converts the path separator character in the nuspec file source to the
character that is correct for the OS that is running the packing
operation. Changes "\" to "/" on Linux and MacOS systems, and
changes "/" to "\" on Windows systems.

Fixes: chocolatey/choco#502
  • Loading branch information
TheCakeIsNaOH authored and gep13 committed May 4, 2021
1 parent bedcd19 commit 979a47d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Core/Authoring/ManifestReader.cs
Expand Up @@ -64,7 +64,7 @@ private static ManifestMetadata ReadMetadata(XElement xElement)
return manifestMetadata;
}

[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
[SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")]
private static void ReadMetadataValue(ManifestMetadata manifestMetadata, XElement element, HashSet<string> allElements)
{
if (element.Value == null)
Expand Down Expand Up @@ -151,10 +151,10 @@ private static void ReadMetadataValue(ManifestMetadata manifestMetadata, XElemen
break;
case "conflicts":
manifestMetadata.Conflicts = value;
break;
break;
case "softwareDisplayName":
manifestMetadata.SoftwareDisplayName = value;
break;
break;
case "softwareDisplayVersion":
manifestMetadata.SoftwareDisplayVersion = value;
break;
Expand Down Expand Up @@ -274,7 +274,7 @@ private static List<ManifestDependencySet> ReadDependencySets(XElement dependenc
return new List<ManifestDependencySet>();
}

// Disallow the <dependencies> element to contain both <dependency> and
// Disallow the <dependencies> element to contain both <dependency> and
// <group> child elements. Unfortunately, this cannot be enforced by XSD.
if (dependenciesElement.ElementsNoNamespace("dependency").Any() &&
dependenciesElement.ElementsNoNamespace("group").Any())
Expand Down Expand Up @@ -340,9 +340,17 @@ private static List<ManifestFile> ReadFilesList(XElement xElement)
string target = file.GetOptionalAttributeValue("target").SafeTrim();
string exclude = file.GetOptionalAttributeValue("exclude").SafeTrim();

// Multiple sources can be specified by using semi-colon separated values.
char separator = Path.DirectorySeparatorChar;

// Multiple sources can be specified by using semi-colon separated values.
files.AddRange(from source in srcElement.Value.Trim(';').Split(';')
select new ManifestFile { Source = source.SafeTrim(), Target = target.SafeTrim(), Exclude = exclude.SafeTrim() });
select new ManifestFile
{
// Replace directory separator in the file src element to the one that is correct for the OS of the packing system.
Source = source.SafeTrim().Replace('/', separator).Replace('\u005c', separator),
Target = target.SafeTrim(),
Exclude = exclude.SafeTrim()
});
}
return files;
}
Expand Down

0 comments on commit 979a47d

Please sign in to comment.