-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Allow non-default encodings to be used in user's script/code #18605
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
Conversation
I did not found an API being out of AutomationEngine which could depend on |
PowerShell doesn't depend on non-default encodings except for the OEM encoding, but user code may depend on them. |
@daxian-dbw Please look CI MacOS fails. Comes from #18567? |
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
The mac CI somehow uses new test changes from a different PR that was merged yesterday. I have rebased the code and CIs should pass hopefully. |
@SeeminglyScience Please review. |
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
@daxian-dbw just an FYI - I had to do more investigation into this PR than was needed due to you doing a little bit of clean up without it being associated to a commit, particularly when looking at |
@kilasuit Thanks for the feedback! |
@SeeminglyScience Friendly ping! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, LGTM!
Great! 👍 |
PR Summary
Fix #18537
Fix the regression to allow non-default encodings to be used in user's script/code.
Move the registration of
CodePagesEncodingProvider
to the static constructor ofAutomationEngine
, which is before theAutomationEngine
constructor is called, which calls intoiss.Bind(...)
that may run user code.Also, almost right after creating an
AutomationEngine
instance inLocalRunspace.DoOpenHelper()
,InitialSessionState.BindRunspace
will be called, which will try loading modules (could be custom modules) that are specified in theInitialSessionState
instance.In fact,
Encoding.GetEncoding('IBM437')
doesn't really work consistently as of today (7.2 or 7.3), here is a simple repro:You will get this failure:
So, this PR is to make it a consistent, predictable behavior.
PR Context
The root cause of the regression is:
UTF8Encoding(false)
withEncoding.Default
part 2 #18356,Encoding.RegisterProvider
will be called on the first time retrieving the default encoding byGetDefaultEncoding()
, which happens when loading thePSReadLine
module on startup. So, the encoding provider gets registered early enough forGetEncoding("IBM437")
to work in user script/code.UTF8Encoding(false)
withEncoding.Default
part 2 #18356,Encoding.RegisterProvider
won't be called untilGetOEMEncoding()
is called, which happens pretty late -- until you run a cmdlet that accessesEncodingConversion
. So, the encoding provider is not registered whenGetEncoding("IBM437")
is used in user script/code.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.