Skip to content

fix(cleanpath): use forward slash as path separator on all platforms (#87)#89

Open
SAY-5 wants to merge 1 commit intospf13:mainfrom
SAY-5:fix/cleanpath-windows-separator-87
Open

fix(cleanpath): use forward slash as path separator on all platforms (#87)#89
SAY-5 wants to merge 1 commit intospf13:mainfrom
SAY-5:fix/cleanpath-windows-separator-87

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 23, 2026

Summary

CleanPath split and joined on filepath.Separator, which is \ on Windows. Since both \ and / are stripped by CharacterFilterRegex, on Windows the strings.Split call never matched, the entire input became a single component, and every / was deleted by removeInvalidCharacters. On Unix everything worked fine — the bug was purely Windows.

This made Test_paths fail with e.g.:

--- FAIL: Test_paths/several_dirs
    paths() = foobarbaz, want foo/bar/baz
--- FAIL: Test_paths/example
    paths() = foobarbazqux, want foo/barbazqux

Fix: split and join on a literal / on every platform. Forward slash is the portable separator the tests already use, and back slash is already removed by the invalid-character filter, so the cleaning behaviour is unchanged on Unix and matches the documented expectations on Windows.

Fixes #87

Test plan

  • go build ./...
  • go test ./... (Unix) passes
  • GOOS=windows go test -c ./... compiles cleanly
  • Manually traced all Test_paths cases: each produces the expected string under both separators

CleanPath split and joined on filepath.Separator which is '\\' on
Windows. Since '\\' (and '/') are both stripped by
CharacterFilterRegex, splitting on '\\' on Windows collapsed any
forward-slash path into one component and lost every '/' separator
— e.g. CleanPath("foo/bar/baz") returned "foobarbaz" on Windows
while returning "foo/bar/baz" on Unix. That also broke Test_paths
on Windows.

Use a literal '/' as the path separator. Forward slash is the
portable separator already used throughout the test fixtures, and
back slash is already removed by the invalid-character filter, so
the behaviour is now identical across platforms.

Fixes spf13#87

Signed-off-by: SAY-5 <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test_paths fails on Windows: hardcoded forward-slash separators

1 participant