Skip to content

UNC paths are broken when parsing file:// URIs (authority ignored, round-trip fails) #557

@t-onoz

Description

@t-onoz

Title

UNC paths are broken when parsing file:// URIs (authority ignored, round-trip fails)


Description

First of all, thank you for maintaining this great library — it’s very useful and appreciated.

I’ve encountered an issue when handling UNC paths via file:// URIs, where the authority component is ignored and the path is incorrectly interpreted as a local path.


Reproduction

from upath import UPath

p = UPath(r'\\server\share\file')
uri = p.as_uri()
print(uri)
# 'file://server/share/file'

p2 = UPath(uri)
print(p2)
# 'file://C://server/share/file'

Expected behavior

file://server/share/file represents a UNC path and should round-trip correctly:

UPath("file://server/share/file")
# -> WindowsUPath('//server/share/file')

Actual behavior

The authority (server) is dropped and interpreted as part of a local path:

FilePath('C://server/share/file', protocol='file')

This is not equivalent to the original UNC path.


Comparison with pathlib (Python 3.14)

from pathlib import Path

p = Path(r'\\server\share\file')
uri = p.as_uri()

Path.from_uri(uri)
# -> WindowsPath('//server/share/file')  # correct

pathlib correctly preserves UNC semantics, while UPath does not.


Impact

  • Round-trip is broken: p != UPath(p.as_uri())
  • UNC paths are corrupted
  • Produces invalid Windows paths

Suggested fix

When parsing file:// URIs:

  • If netloc (authority) is non-empty → treat as UNC:

    //{netloc}{path}
    
  • Otherwise → handle as a local path (file:///C:/...)


Environment

  • upath: 0.3.10
  • Python: 3.14
  • OS: Windows

Notes

I searched existing issues using:

  • "UNC"
  • "file URI"

but could not find a matching report.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions