8

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!

Brett Jenkins
  • 192
  • 2
  • 9
  • What is you PowerShell version. Be curious to check both shells to be sure you don't have switches used on your shortcuts. _Possible_ this is a bug but would need the version to be sure. – Matt Jan 31 '17 at 14:09
  • Reproducible on PowerShell 5 on Windows 10 and Windows 7. – BenH Jan 31 '17 at 14:58
  • @Matt 5.1.14393.693 Same on both consoles – Brett Jenkins Jan 31 '17 at 15:09
  • 3
    Here is the difference: `[System.UriParser].GetField('s_QuirksVersion', [Reflection.BindingFlags] 'Static, NonPublic').GetValue($null)`. – user4003407 Jan 31 '17 at 16:42
  • @PetSerAl interesting, I don't see this quirksversion documented anywhere unless I'm missing something – Brett Jenkins Feb 01 '17 at 15:18
  • @britcowboy There is always the [source](https://referencesource.microsoft.com/System/a.html#c1b4c38749000c9b). – user4003407 Feb 01 '17 at 15:54

1 Answers1

2

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.

Community
  • 1
  • 1
Richard Krajunus
  • 809
  • 8
  • 18
  • Is there any way to set this to V3 in PowerShell? (or V2 in ISE?) Some consistency would have saved me a couple of days of my life. – Steve Black May 23 '17 at 04:51