Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EscapeDataString having differing behaviour between Powershell IDE and Powershell console

I'm a bit confused with this issue! I'm building a bigger script and it was working in the ISE but not in a powershell console. I've managed to track it down to the [System.Uri]::EscapeDataString function which seems to be behaving differently between the different environments, for example in my powershell console () ' & ! are not being escaped, where as in the IDE they are all being escaped.

Am I missing something?

My test code:

[System.Uri]::EscapeDataString("/?:@%!$&'/*+,;=()")

ISE output:

%2F%3F%3A%40%25%21%24%26%27%2F%2A%2B%2C%3B%3D%28%29

Powershell Console output:

%2F%3F%3A%40%25!%24%26'%2F*%2B%2C%3B%3D()

Screenshot

Thanks!

like image 348
Brett Jenkins Avatar asked Jan 31 '17 13:01

Brett Jenkins


1 Answers

Here is the difference, per the source: [System.UriParser].GetField('s_QuirksVersion', [Reflection.BindingFlags] 'Static, NonPublic').GetValue($null).

I marked the answer as community wiki because it appeared in the comments, causing the question to appear in searches for unanswered questions.

like image 51
Richard Krajunus Avatar answered Nov 08 '22 04:11

Richard Krajunus