Skip to content

System.Uri .AbsoluteUri duplicates paths #1031

@TylerLeonhardt

Description

@TylerLeonhardt

Pass in a file path with ASCII characters into the Uri constructor and get the AbsoluteUri:

> new Uri("/Users/tyleonha/Code/PowerShell/Misc/foo.ps1").AbsoluteUri
file:///Users/tyleonha/Code/PowerShell/Misc/foo.ps1

Everything looks great. Now pass in a path with non-ASCII characters:

> new Uri("/Users/tyleonha/Code/PowerShell/Misc/测试.ps1").AbsoluteUri
file:///Users/tyleonha/Code/PowerShell/Misc/%E6%B5%8B%E8%AF%95.ps1/Users/tyleonha/Code/PowerShell/Misc/%E6%B5%8B%E8%AF%95.ps1

The file is url encoded correctly but the file path is duplicated.

Same happens if I pass in the path a Uri string:

new Uri("file:///Users/tyleonha/Code/PowerShell/Misc/%E6%B5%8B%E8%AF%95.ps1").AbsoluteUri
file:///Users/tyleonha/Code/PowerShell/Misc/%E6%B5%8B%E8%AF%95.ps1/Users/tyleonha/Code/PowerShell/Misc/%E6%B5%8B%E8%AF%95.ps1

If I add a drive letter, this no longer repros:

> new Uri("C:/Users/tyleonha/Code/PowerShell/Misc/测试.ps1").AbsoluteUri
file:///C:/Users/tyleonha/Code/PowerShell/Misc/%E6%B5%8B%E8%AF%95.ps1

We know that the path passed in is absolute... so I'm a bit confused as to why this duplication is happening.

I'm running this on macOS Mojave with .NET Core 3.1 (via PowerShell).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions