IDE和Powershell控制台之间具有不同的行为

IDE和Powershell控制台之间具有不同的行为

本文介绍了EscapeDataString在Powershell IDE和Powershell控制台之间具有不同的行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点混淆这个问题!我正在构建一个更大的脚本,它在ISE中工作,但不在一个powerhell控制台中。我已经设法跟踪到[System.Uri] :: EscapeDataString函数,它似乎在不同环境之间的行为不同,例如在我的powershell console()'& !没有被逃脱,在IDE中他们都被逃脱了。



我错过了什么?



我的测试代码:

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

ISE输出:

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

Powershell控制台输出:

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


谢谢!

解决方案

根据: [System.UriParser] .GetField('s_QuirksVersion',[Reflection.BindingFlags]'Static,NonPublic')。GetValue($ null)



我将答案标记为社区wiki,因为它出现在评论中,导致问题出现在搜索未解答的问题。


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()

Thanks!

解决方案

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.

这篇关于EscapeDataString在Powershell IDE和Powershell控制台之间具有不同的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 19:47