Building a package on Linux fails if the description has encoded xml special character(s)
Closed this issue · 2 comments
This is a companion issue to chocolatey/choco#2382
What You Are Seeing?
When running on Mono on Linux, if choco pack
is run on a .nuspec
that contains encoded xml special character(s), it fails. Specifically with using <
and >
as shown in dust. This package does build without issues on Windows.
It fails with Unexpected end of file has occurred. The following elements are not closed:
I have not tested this to check if other encoded special characters work or not.
What is Expected?
That choco pack
works.
How Did You Get This To Happen? (Steps to Reproduce)
- Download the dust package source at this commit:
https://github.com/Starz0r/ChocolateyPackagingScripts/tree/ca30cc5f3eba19f535c82df46b57a2efc8bdf932 - Replace the nuspec version element with a valid version.
- Run
choco pack
Workaround
Wrapping the description in with cdata
will allow choco pack
to work.
Example:
https://github.com/mkevenaar/chocolatey-packages/blob/master/automatic/anyrail6/anyrail6.nuspec#L48
Output Log
Full Log Output
Chocolatey v0.11.2-26-gefda91af
Unable to set trace logging:
Object reference not set to an instance of an object
Chocolatey is running on Linux v 5.10.0.0
Attempting to delete file "/opt/chocolatey/chocolatey.dll.old".
Attempting to delete file "/opt/chocolatey/choco.exe.old".
Command line: /opt/chocolatey/choco.exe pack --verbose --debug --trace --allow-unofficial
Received arguments: pack --verbose --debug --trace --allow-unofficial
RemovePendingPackagesTask is now ready and waiting for PreRunMessage.
Sending message 'PreRunMessage' out if there are subscribers...
[Pending] Removing all pending packages that should not be considered installed...
Performing validation checks.
Global Configuration Validation Checks:
- Package Exit Code / Exit On Reboot = Checked
System State Validation Checks:
The source 'https://chocolatey.org/api/v2/' evaluated to a 'normal' source type
NOTE: Hiding sensitive configuration data! Please double and triple
check to be sure no sensitive data is shown, especially if copying
output to a gist for review.
Configuration: CommandName='pack'|CacheLocation='/tmp/chocolatey'|
ContainsLegacyPackageInstalls='True'|
CommandExecutionTimeoutSeconds='2700'|WebRequestTimeoutSeconds='30'|
Sources='https://chocolatey.org/api/v2/'|SourceType='normal'|
Debug='True'|Verbose='True'|Trace='True'|Force='False'|Noop='False'|
HelpRequested='False'|UnsuccessfulParsing='False'|RegularOutput='True'|
QuietOutput='False'|PromptForConfirmation='False'|
AcceptLicense='False'|
AllowUnofficialBuild='True'|AllVersions='False'|
SkipPackageInstallProvider='False'|Prerelease='False'|ForceX86='False'|
OverrideArguments='False'|NotSilent='False'|
ApplyPackageParametersToDependencies='False'|
ApplyInstallArgumentsToDependencies='False'|IgnoreDependencies='False'|
AllowMultipleVersions='False'|AllowDowngrade='False'|
ForceDependencies='False'|Information.PlatformType='Linux'|
Information.PlatformVersion='5.10.0.0'|
Information.PlatformName='Linux'|
Information.ChocolateyVersion='0.12.0.0'|
Information.ChocolateyProductVersion='0.11.2-26-gefda91af'|
Information.FullName='chocolatey, Version=0.12.0.0, Culture=neutral, PublicKeyToken=fd112f53c3ab578c'|
Information.Is64BitOperatingSystem='True'|
Information.Is64BitProcess='True'|Information.IsInteractive='False'|
Information.UserName="REDACTED'|Information.UserDomainName='REDACTED'|
Information.IsUserAdministrator='False'|
Information.IsUserSystemAccount='False'|
Information.IsUserRemoteDesktop='False'|
Information.IsUserRemote='True'|
Information.IsProcessElevated='False'|
Information.IsLicensedVersion='False'|Information.LicenseType='Foss'|
Information.CurrentDirectory='REDACTED'|
Features.AutoUninstaller='True'|Features.ChecksumFiles='True'|
Features.AllowEmptyChecksums='False'|
Features.AllowEmptyChecksumsSecure='True'|
Features.FailOnAutoUninstaller='False'|
Features.FailOnStandardError='False'|Features.UsePowerShellHost='True'|
Features.LogEnvironmentValues='False'|Features.LogWithoutColor='False'|
Features.VirusCheck='False'|
Features.FailOnInvalidOrMissingLicense='False'|
Features.IgnoreInvalidOptionsSwitches='True'|
Features.UsePackageExitCodes='True'|
Features.UseEnhancedExitCodes='False'|
Features.UseFipsCompliantChecksums='False'|
Features.ShowNonElevatedWarnings='True'|
Features.ShowDownloadProgress='True'|
Features.StopOnFirstPackageFailure='False'|
Features.UseRememberedArgumentsForUpgrades='False'|
Features.IgnoreUnfoundPackagesOnUpgradeOutdated='False'|
Features.SkipPackageUpgradesWhenNotInstalled='False'|
Features.RemovePackageInformationOnUninstall='False'|
Features.ExitOnRebootDetected='False'|
Features.LogValidationResultsOnWarnings='True'|
Features.UsePackageRepositoryOptimizations='True'|
Features.ScriptsCheckLastExitCode='False'|
ListCommand.LocalOnly='False'|
ListCommand.IdOnly='False'|ListCommand.IncludeRegistryPrograms='False'|
ListCommand.PageSize='25'|ListCommand.Exact='False'|
ListCommand.ByIdOnly='False'|ListCommand.ByTagOnly='False'|
ListCommand.IdStartsWith='False'|ListCommand.OrderByPopularity='False'|
ListCommand.ApprovedOnly='False'|
ListCommand.DownloadCacheAvailable='False'|
ListCommand.NotBroken='False'|
ListCommand.IncludeVersionOverrides='False'|
UpgradeCommand.FailOnUnfound='False'|
UpgradeCommand.FailOnNotInstalled='False'|
UpgradeCommand.NotifyOnlyAvailableUpgrades='False'|
UpgradeCommand.ExcludePrerelease='False'|
NewCommand.AutomaticPackage='False'|
NewCommand.UseOriginalTemplate='False'|SourceCommand.Command='unknown'|
SourceCommand.Priority='0'|SourceCommand.BypassProxy='False'|
SourceCommand.AllowSelfService='False'|
SourceCommand.VisibleToAdminsOnly='False'|
FeatureCommand.Command='unknown'|ConfigCommand.Command='unknown'|
ApiKeyCommand.Remove='False'|PinCommand.Command='unknown'|
OutdatedCommand.IgnorePinned='False'|
ExportCommand.IncludeVersionNumbers='False'|Proxy.BypassOnLocal='True'|
_ Chocolatey:ChocolateyPackCommand - Normal Run Mode _
Attempting to build package from 'dust.nuspec'.
Attempting to delete file "REDACTED".
Sending message 'PostRunMessage' out if there are subscribers...
Not able to cleanup NuGet temp folders. Failure was Path to combine cannot be empty. Tried to combine null with ''. Method called from 'delete_directory'
Chocolatey had an error occur:
System.Xml.XmlException: Unexpected end of file has occurred. The following elements are not closed: dir, dir, dir, dir, dir, dir, dir, dir, and_more, another_dir, dir, dir. Line 33, position 173.
at System.Xml.XmlTextReaderImpl.Throw (System.Exception e) [0x00027] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlTextReaderImpl.Throw (System.String res, System.String arg) [0x00029] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlTextReaderImpl.Throw (System.Int32 pos, System.String res, System.String arg) [0x0000c] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlTextReaderImpl.ThrowUnclosedElements () [0x000cc] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlTextReaderImpl.ParseElementContent () [0x001eb] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlTextReaderImpl.Read () [0x00085] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlLoader.LoadNode (System.Boolean skipOverWhitespace) [0x0025b] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlLoader.ParsePartialContent (System.Xml.XmlNode parentNode, System.String innerxmltext, System.Xml.XmlNodeType nt) [0x00096] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlLoader.LoadInnerXmlElement (System.Xml.XmlElement node, System.String innerxmltext) [0x00000] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.Xml.XmlElement.set_InnerXml (System.String value) [0x0000b] in <7ff8f64b3a334d14838f500f5ad27e36>:0
at System.IO.Packaging.PackagePropertiesPart.WriteTo (System.Xml.XmlTextWriter writer) [0x00245] in <8f8261ee75c34c9cb0a71d0993973faa>:0
at System.IO.Packaging.PackageProperties.Flush () [0x00012] in <8f8261ee75c34c9cb0a71d0993973faa>:0
at System.IO.Packaging.Package.Flush () [0x0002d] in <8f8261ee75c34c9cb0a71d0993973faa>:0
at System.IO.Packaging.Package.System.IDisposable.Dispose () [0x00008] in <8f8261ee75c34c9cb0a71d0993973faa>:0
at NuGet.PackageBuilder.Save (System.IO.Stream stream) [0x00172] in <0446c6bfcd824d528312261f49bc47fe>:0
at chocolatey.infrastructure.app.nuget.NugetPack.BuildPackage (NuGet.PackageBuilder builder, chocolatey.infrastructure.filesystem.IFileSystem fileSystem, System.String outputPath) [0x00056] in <b562e3be71e5414f9c863081fc9cfe6a>:0
at chocolatey.infrastructure.app.services.NugetService.pack_run (chocolatey.infrastructure.app.configuration.ChocolateyConfiguration config) [0x001fb] in <b562e3be71e5414f9c863081fc9cfe6a>:0
at chocolatey.infrastructure.app.services.ChocolateyPackageService.pack_run (chocolatey.infrastructure.app.configuration.ChocolateyConfiguration config) [0x00020] in <b562e3be71e5414f9c863081fc9cfe6a>:0
at chocolatey.infrastructure.app.commands.ChocolateyPackCommand.run (chocolatey.infrastructure.app.configuration.ChocolateyConfiguration configuration) [0x00000] in <b562e3be71e5414f9c863081fc9cfe6a>:0
at chocolatey.infrastructure.app.runners.GenericRunner.run (chocolatey.infrastructure.app.configuration.ChocolateyConfiguration config, SimpleInjector.Container container, System.Boolean isConsole, System.Action`1[T] parseArgs) [0x000e4] in <b562e3be71e5414f9c863081fc9cfe6a>:0
at chocolatey.infrastructure.app.runners.ConsoleApplication.run (System.String[] args, chocolatey.infrastructure.app.configuration.ChocolateyConfiguration config, SimpleInjector.Container container) [0x000d6] in <b562e3be71e5414f9c863081fc9cfe6a>:0
at chocolatey.console.Program.Main (System.String[] args) [0x0036a] in <ddda087b130440f1b08e60acf2c82fe8>:0
Exiting with 1
Here is where the issue actually crops up:
https://github.com/chocolatey/nuget-chocolatey/blob/2.11_adds/src/Core/Authoring/PackageBuilder.cs#L305-L312
It is to do with the description put in the .psmdcp
file, not the .nuspec
.
There is an issue open on mono for this here:
mono/mono#21227
Here is a list of the possibly affected metadata elements:
Item | Affected? |
---|---|
package.PackageProperties.Creator = String.Join(",", Authors); | Yes, tested |
package.PackageProperties.Description = Description; | Yes, tested |
package.PackageProperties.Identifier = Id; | No, package ids cannot have xml special chars |
package.PackageProperties.Version = Version.ToString(); | No, versions cannot have xml special chars |
package.PackageProperties.Language = Language; | Should not be |
package.PackageProperties.Keywords = ((IPackageMetadata)this).Tags; | Yes, tested |
package.PackageProperties.Title = Title; | Yes, tested |
package.PackageProperties.LastModifiedBy = CreatorInfo(); | Should not be |