英文:
PowerShell [uri] Types Accelerator produces different AbsoluteUri
问题
我有一个本地文件($URLsFile),其中包含一组URL:
http://WIND451325/Dev/Application.aspx__%__dev.com
http://WIND451326/Dev/Application.aspx__%__dev.com
在使用[uri]类型加速器与Get-Content命令时:
[uri[]]$ArrayURLs = Get-Content -Path $URLsFile
我注意到AbsoluteUri属性的值发生了一些变化,__%__
变成了 __%25__
:
foreach ($item in $ArrayURLs)
{
$item.AbsoluteUri
}
http://WIND451325/Dev/Application.aspx__%25__dev.com
http://WIND451326/Dev/Application.aspx__%25__dev.com
在查阅官方文档之后:
https://learn.microsoft.com/en-us/dotnet/api/system.uri?view=net-7.0
我没有找到与此主题相关的任何参考信息。
英文:
I have a local file ($URLsFile), which contains a list of URLs:
http://WIND451325/Dev/Application.aspx__%__dev.com
http://WIND451326/Dev/Application.aspx__%__dev.com
When using the [uri] Types Accelerator with the Get-Content command:
[uri[]]$ArrayURLs = Get-Content -Path $URLsFile
I've noticed some changes in the value of the AbsoluteUri property, as __%__
changed to __%25__
:
foreach ($item in $ArrayURLs)
{
$item.AbsoluteUri
}
http://WIND451325/Dev/Application.aspx__%25__dev.com
http://WIND451326/Dev/Application.aspx__%25__dev.com
After going through the official documentation:
https://learn.microsoft.com/en-us/dotnet/api/system.uri?view=net-7.0
I could not find any reference to the subject.
答案1
得分: 2
可以使用具有 `dontEscape` 参数设置为 `$true` 的[重载](https://learn.microsoft.com/en-us/dotnet/api/system.uri.-ctor?view=net-8.0#system-uri-ctor(system-string-system-boolean))。
$ArrayURLs = Get-Content -Path $URLsFile |
ForEach-Object { [uri]::new($_, $true) }
在新版本的 PowerShell 7+ 中,此构造函数已被弃用,您应该使用UriCreationOptions
重载。
$options = [System.UriCreationOptions]@{
DangerousDisablePathAndQueryCanonicalization = $true
}
$ArrayURLs = Get-Content -Path $URLsFile |
ForEach-Object { [uri]::new($_, [ref] $options) }
英文:
<!-- language-all: sh -->
You can use the overload with dontEscape
set to $true
.
$ArrayURLs = Get-Content -Path $URLsFile |
ForEach-Object { [uri]::new($_, $true) }
This ctor is obsolete, in newer versions of PowerShell 7+, you should use the UriCreationOptions
overload instead.
$options = [System.UriCreationOptions]@{
DangerousDisablePathAndQueryCanonicalization = $true
}
$ArrayURLs = Get-Content -Path $URLsFile |
ForEach-Object { [uri]::new($_, [ref] $options) }
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论