Use forward slash as the path separator on all platforms
files package and the compiler internals now use / as the separator on every platform, including Windows.
Motivation
Cross-platform path code required every layer to normalize separators independently. The C runtime, the compiler, the stdlib, and each tool all had their own #ifdef blocks choosing \ on Windows and / elsewhere. Missing one meant backslashes leaking through on Windows, causing silent lookup failures when one layer stored a path with \ and another searched for it with /.
This PR makes / the canonical separator everywhere: the C runtime normalizes at ingress, the compiler does the same, Path.sep() returns "/" unconditionally, and Path.clean() converts any remaining \ on Windows.
File Map
- packages/files/path.pony +65 −51
- packages/files/directory.pony +1 −1
- packages/files/_non_root_test.pony +102 −96
- tools/pony-lsp/uris.pony +18 −23
- tools/pony-lsp/corral.pony +2 −2
- tools/pony-lint/ignore_matcher.pony +2 −10
- tools/pony-doc/path_sanitize.pony +2 −11
- tools/pony-doc/tqfn.pony +4 −13
- tools/pony-dep/archive_encoder.pony +1 −5
- tools/pony-dep/content_hash.pony +1 −6
- tools/pony-dep/pack.pony +1 −5
- .release-notes/next-release.md +34 −0
- CHANGELOG.md +2 −0
Behavioral Changes
Paths are /-separated on all platforms
Path.sep() returns "/" on Windows (previously "\\"). Path.cwd(), Path.canonical(), Path.join(), Path.clean(), and all other path operations produce /-separated paths. Windows code that compared paths against string literals with \ will stop matching.
Path.normcase() only lowercases
On Windows, normcase() previously replaced / with \ and lowercased the path. It now only lowercases.
Path.from_slash() and Path.to_slash() removed
These functions served no purpose when all paths are already /-separated. Any code calling them will fail to compile.
Path.to_os() added
Converts / to \ on Windows. Returns the path unchanged on other platforms.
cmd.exe footgun: cmd.exe interprets / as an option flag, not a path separator. Code that passes paths to cmd.exe or .bat files must wrap them with Path.to_os() to convert back to \. Win32 API calls accept / without issue — the footgun is specifically at the shell boundary.
dir(), base(), ext(), split() handle both separators on Windows
These functions now use an internal _rfind_sep helper that finds both / and \ on Windows. Paths from external sources (e.g. __loc.file()) that still contain \ are handled correctly without requiring a prior clean().
API Changes
fun tag sep(): String => ifdef windows then "\\" else "/" end
fun tag sep(): String => "/"
fun normcase(path: String): String =>
if Platform.windows() or Platform.osx() then
var p = path.lower()
ifdef windows then
p = Path.from_slash(p)
end
p
else
path
endfun normcase(path: String): String =>
if Platform.windows() or Platform.osx() then
path.lower()
else
path
endfun from_slash(path: String): String =>
ifdef windows then
path.clone() .> replace("/", "\\")
else
path
end
fun to_slash(path: String): String =>
ifdef windows then
path.clone() .> replace("\\", "/")
else
path
end// Removed. Delete any calls to these functions.
// No equivalent. Code that needed backslash paths // on Windows used Path.from_slash().
fun to_os(path: String): String =>
ifdef windows then
// replaces '/' with '\\' byte by byte
let s = path.clone()
// ...
s
else
path
endfun split(path: String,
separator: String = Path.sep()
): (String, String) =>
try
let i = path.rfind(separator)?.usize()
(clean(path.trim(0, i)),
path.trim(i + 1))
else
("", path)
endfun split(path: String,
separator: String = Path.sep()
): (String, String) =>
try
let i = _rfind_sep(path)?.usize()
(clean(path.trim(0, i)),
path.trim(i + 1))
else
("", path)
endPublic API Surface
/ as the separator on every platform.- fun is_sep(c: U8): Bool
- fun tag sep(): String
- fun is_abs(path: String): Bool
- fun join(path: String, next_path: String): String
- fun clean(path: String): String
- fun normcase(path: String): String
- fun cwd(): String
- fun abs(path: String): String
- fun rel(to: String, target: String): String ?
- fun split(path: String, separator: String = Path.sep()): (String, String)
- fun base(path: String, with_ext: Bool = true): String
- fun dir(path: String): String
- fun ext(path: String): String
- fun volume(path: String): String
- fun to_os(path: String): String
- fun canonical(path: String): String ?
- fun is_list_sep(c: U8): Bool
- fun list_sep(): String
- fun split_list(path: String): Array[String] iso^
- fun random(len: USize = 6): String
Architecture
The change normalizes paths at four ingress points. Everything downstream receives /-separated paths without needing its own normalization.
Release Notes
Use forward slash as the path separator on all platforms
All paths in the files package now use / as the separator on every platform, including Windows. Paths from Path.cwd() and Path.canonical() are /-separated, Path.sep() returns "/" unconditionally, and Path.clean() converts \ to / on Windows.
Path.is_sep() still accepts \ on Windows for parsing external input. Use Path.to_os() when a backslash path is needed for Windows shell commands.
Path.normcase() now only lowercases the path on case-insensitive platforms. It no longer replaces / with \ on Windows.
Before:
if path == "C:\\Users\\me\\project" then // ... end
After:
if path == "C:/Users/me/project" then // ... end
Code that passes paths to Windows shell commands should use Path.to_os():
let os_path = Path.to_os(path)
Remove Path.from_slash and Path.to_slash
Path.from_slash() and Path.to_slash() have been removed. All paths use / as the separator on every platform, so these functions served no purpose. Remove any calls to them.