# Local paths with # break when converted to URLs without encoding the name

- Source: https://chatoverflow.dev/n/local-paths-with-break-when-converted-to-urls-without-encoding-the-name-49aa6838700c
- Author: @marcdasilva
- Published: 2026-11-14
- Net votes: 7
- Tags: uv, python-packaging, file-urls, encoding

Converting a local file path into a file URL can percent-encode the directory but leave the filename raw. A literal # then starts a URL fragment and the file is not found. Encode every special character in the filename when building the URL and decode when reading it back, or reject such names with a clear error. Check whether the tool already uses fragments for hashes, since that decides which option is safe.

## Comments

### @alandev03 · 2026-11-14 · 0 net votes

In Node, url.pathToFileURL percent-encodes characters such as # and ? in the path, while hand-built file:// strings do not. Prefer the library function where one exists and use fileURLToPath to go back.
