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

Don't output NULL between characters #3036

Closed
2 tasks done
vbjay opened this issue Feb 19, 2023 · 12 comments
Closed
2 tasks done

Don't output NULL between characters #3036

vbjay opened this issue Feb 19, 2023 · 12 comments

Comments

@vbjay
Copy link

vbjay commented Feb 19, 2023

Checklist

  • I have verified this is the correct repository for opening this issue.
  • I have verified no other issues exist related to my request.

Is Your Feature Request Related To A Problem? Please describe.

Output isn't markdown friendly. Running choco feature >> c:\someMDFile.md results in
image

Describe The Solution. Why is it needed?

Don't output nulls between chars.

Additional Context

Bonus points if you have a flag to alter output to make it valid checkbox markdown like so

image

SUPER BONUS points!!!! 🚀

Allow us to generate a markdown file from current config and then let us alter the markdown file with the changed features and then import that file back in to adjust features.


vs code extension for markdown preview is
https://marketplace.visualstudio.com/items?itemName=shd101wyy.markdown-preview-enhanced

Related Issues

No response

@vbjay
Copy link
Author

vbjay commented Feb 19, 2023

microsoft/WSL#4607 (comment) fixed the null byte issue. But would love the valid markdown syntax adding -{space} in front of each [ in the output.

[console]::OutputEncoding = New-Object System.Text.UnicodeEncoding

This may help too https://stackoverflow.com/questions/40098771/changing-powershells-default-output-encoding-to-utf-8

@pauby
Copy link
Member

pauby commented Feb 19, 2023

What are you using to see the NULL bytes in the first two screenshots?

@vbjay
Copy link
Author

vbjay commented Feb 19, 2023

Vscode. I have it set to show the hidden characters.

@pauby
Copy link
Member

pauby commented Feb 19, 2023

If you mean the Render whitespace option, I have that set and see this when running choco feature > test.md from PowerShell 7.3.2. Running from zsh gives me the same.

image

@vbjay
Copy link
Author

vbjay commented Feb 19, 2023

I was in windows PowerShell. Encoding was 1252. Reading the stack overflow I linked earlier you will understand it. So easy fix to force my encoding by either switching to out-file with encoding specified or setting the console output or coding.

However, my bonus feature parts of valid markdown export and potential import would be great.

@vbjay
Copy link
Author

vbjay commented Feb 19, 2023

Shows the idea

$hd=@"
# Chocolatey Features

"@

$fl = ".\test.md"
$hd|Out-File -FilePath $fl -Encoding utf8

choco feature |Out-File -FilePath $fl -Encoding utf8 -Append

md edit

@vbjay
Copy link
Author

vbjay commented Feb 19, 2023

image

@pauby
Copy link
Member

pauby commented Feb 19, 2023

The issue I want to concentrate on is the first one - the NULL output. I need to understand if this is a Chocolatey issue, we need to be able to reproduce it. So far I've not been able to do that (I have Render Whitespace and Render Control Characters turned on).

If this is a bug in Chocolatey, can you raise a new issue and complete the Bug report?

Bonus points if you have a flag to alter output to make it valid checkbox markdown like so
Allow us to generate a markdown file from current config and then let us alter the markdown file with the changed features and then import that file back in to adjust features.

This is not something we would look to implement.

@vbjay
Copy link
Author

vbjay commented Feb 19, 2023

It is potentially if it is sending output in 1252 encoding and it looks like utf16LE might be playing a part. Read the stackoverflow I linked to understand why it isn't defaulted to utf8 in windows powershell. When I open windows PowerShell I get

[console]::OutputEncoding
IsSingleByte      : True
BodyName          : IBM437
EncodingName      : OEM United States
HeaderName        : IBM437
WebName           : IBM437
WindowsCodePage   : 1252
IsBrowserDisplay  : False
IsBrowserSave     : False
IsMailNewsDisplay : False
IsMailNewsSave    : False
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 437

If you just run choco feature > somefile.txt and open the file you will see the issue.

@pauby
Copy link
Member

pauby commented Feb 19, 2023

If you just run choco feature > somefile.txt and open the file you will see the issue.

I don't see the issue. Can you raise a bug report, so we can capture all the information?

@vbjay
Copy link
Author

vbjay commented Feb 19, 2023

Sure but run the command I provided in windows powershell

Note : from stackoverflow

Out-File and > / >> create "Unicode" - UTF-16LE - files by default - in which every ASCII-range character (too) is represented by 2 bytes - which notably differs from Set-Content / Add-Content (see next point);

https://stackoverflow.com/questions/40098771/changing-powershells-default-output-encoding-to-utf-8 READ full stack overlow!
Basically I think this is environment specific. The stack overflow gets into good detail. Changing the encoding by setting console::OutputEncoding solved the problem.

@pauby
Copy link
Member

pauby commented Feb 19, 2023

Sure but run the command I provided in windows powershell

I spun up a Windows 10 VM and used Windows PowerShell to run the command last time. I didn't see the NULL bytes.

https://stackoverflow.com/questions/40098771/changing-powershells-default-output-encoding-to-utf-8 READ full stack overlow!
Basically I think this is environment specific. The stack overflow gets into good detail. Changing the encoding by setting console::OutputEncoding solved the problem.

I did read the Stack Overflow post (thanks for linking to it) and it sounded to me like a PowerShell session / environment issue. But, when I asked:

If this is a bug in Chocolatey, can you raise a new issue and complete the Bug report?

you responded with:

It is potentially if it is sending output in 1252 encoding and it looks like utf16LE might be playing a part.

So, I wanted to reproduce the issue to see if it was a Chocolatey problem.

Basically I think this is environment specific. The stack overflow gets into good detail. Changing the encoding by setting console::OutputEncoding solved the problem.

If this is the root cause, I'll go ahead and close this just now. We can always re-open it again if needed.

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