Wave icon indicating copy to clipboard operation
Wave copied to clipboard

Respect Unix filename separators in path component helpers

Open LunaStev opened this issue 1 month ago • 0 comments

Problem

path_is_abs follows target-specific rules, but path_is_sep treats both slash and backslash as separators on every target. Consequently, basename/dirname/join operations misinterpret valid Unix filenames containing a backslash.

Starting points: separator policy and component analysis. #529 fixed absolute-path classification, not this component-parsing mismatch.

Reproduction

Audited canonical master 7a8361d5c10ec3e66fc9fe4a5801622afb6bf631 on Linux amd64. Reproduced with the public v0.2.1-pre-beta Linux amd64 compiler (LLVM 21.1.8) and this checkout's std; the compiler/std source trees match the release. Set WAVEC to the extracted package's absolute wavec path and run commands from the repository root.

import("std::path::analyze")::{path_basename_start, path_basename_len};
fun main() -> i32 {
    println("start={} len={}", path_basename_start("a\\b"), path_basename_len("a\\b"));
    return 0;
}

Run "$WAVEC" --std-root "$PWD/std" run repro.wave. Linux output is start=2 len=1, although a\b is one three-byte filename component. Native Unix interpretation would give start=0 len=3. A leading backslash is also treated as a root by component analysis while path_is_abs returns false.

Scope

Use a consistent target policy for basename, dirname, extension and joining while preserving Windows slash/backslash support. This is a compatibility change for callers using Unix builds to manipulate Windows-style text. Please mention @LunaStev to discuss the compatibility policy before starting implementation. Difficulty: medium.

Completion criteria

  • [ ] Unix backslashes remain part of filename components across the affected helpers.
  • [ ] Windows separator and drive-root behavior remains covered by native-target tests.
  • [ ] Root detection and absolute-path classification no longer contradict one another for a leading backslash on Unix.

LunaStev avatar Oct 05 '26 12:10 LunaStev