Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building a package on Linux fails if the description has encoded xml special character(s) #2382

Closed
TheCakeIsNaOH opened this issue Sep 27, 2021 · 5 comments
Assignees
Milestone

Comments

@TheCakeIsNaOH
Copy link
Member

TheCakeIsNaOH commented Sep 27, 2021

This is a companion issue to: chocolatey/nuget-chocolatey#27

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 &lt and &gt 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)

  1. Download the dust package source at this commit:
    https://github.com/Starz0r/ChocolateyPackagingScripts/tree/ca30cc5f3eba19f535c82df46b57a2efc8bdf932
  2. Replace the nuspec version element with a valid version.
  3. 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

@TheCakeIsNaOH
Copy link
Member Author

I think it is pretty likely that this is an issue in nuget-chocolatey or in mono, not in the choco code base.

Debugging this is complicated because I can't get the vscode-mono-debug extension to debug the nuget.core.dll, and because the actual error shows up when the System.IO.Packaging.Package is being disposed of.

@TheCakeIsNaOH
Copy link
Member Author

TheCakeIsNaOH commented Sep 29, 2021

Ok, this seems to be another mono bug like #2076. Sigh. I don't think I've had anyone look at my PR to fix the previous issue I found, and it's been open since May.

I've got a POC program using System.IO.Packaging that works on Windows, but fails on Mono.

using System;
using System.IO;
using System.IO.Packaging;

namespace test
{
   public class test
   {
      public static void Main(string[] args)
      {
          FileStream stream = new FileStream("file.zip", FileMode.Create);
          using (Package package = Package.Open(stream, FileMode.Create))
          {
                package.PackageProperties.Description = "Usage: dust -p <dir>;  (full-path - does not shorten the path of the subdirectories)";
          }
          
      }
   } 
}

@TheCakeIsNaOH
Copy link
Member Author

I've opened an issue with mono here: mono/mono#21227

@gep13
Copy link
Member

gep13 commented Oct 14, 2021

A fix has been proposed by @TheCakeIsNaOH is a lie here: chocolatey/nuget-chocolatey#27 which we will pull into chocolatey/choco in the next release.

gep13 added a commit that referenced this issue Oct 14, 2021
This new assembly includes a fix to address an issue when attempting to
pack a Chocolatey nuspec file that contains escaped XML characters on a
Linux machine.  During testing, it was found that a nuspec file that
contains escaped XML characters would work fine on a Windows machine,
but the build would fail on a Linux machine.  A change was applied
upstream to correct this inconsistency.
@gep13 gep13 closed this as completed Oct 14, 2021
gep13 added a commit that referenced this issue Oct 14, 2021
This doesn't happen automagically, since this is a direct reference to
the assembly, rather than an actual NuGet package reference.
@gep13
Copy link
Member

gep13 commented Oct 14, 2021

@TheCakeIsNaOH I have just tested this, and all seems to be working now! Thanks again for getting this fixed up!

TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Oct 15, 2021
…sole

In commit 545ca6c, the chocolatey.console cs project was not updated,
unlike the other projects. This updates that project in line with the
others.
gep13 added a commit that referenced this issue Oct 15, 2021
(#2382) Reference new NuGet.Core assembly in chocolatey.console
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants