Skip to content

feat: add Windows support by handling empty path case in PathSplit function #5944

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pcanilho
Copy link

@pcanilho pcanilho commented Jul 16, 2025

Goal: Fix PathSplit function to handle empty path case for Windows support

Context: This PR fixes an issue I was having when adding Windows support for some of my utilities by updating the function to handle the case when is empty.

The issue

When running on Windows, I was getting errors because the function wasn't handling empty paths correctly. The problem occurs because Windows uses backslashes (\) as path separators, so when resolves to \, the path splitting logic behaves differently than on Unix systems.
For example, I was seeing errors like this locally:

C:\Users\<user>\AppData\Local\Temp\<my_local_git>@<local_ref>

Causing a stack overflow:

click here to see the stack trace... ❗️
fatal error: stack overflow

runtime stack:
runtime.throw({0x7ff62c817a83?, 0x7ff62a2ef630?})
        C:/Program Files/Go/src/runtime/panic.go:1101 +0x38 fp=0x26bffffd60 sp=0x26bffffd30 pc=0x7ff62a331418
runtime.newstack()
        C:/Program Files/Go/src/runtime/stack.go:1107 +0x464 fp=0x26bffffea0 sp=0x26bffffd60 pc=0x7ff62a318094
runtime.morestack()
        C:/Program Files/Go/src/runtime/asm_arm64.s:342 +0x70 fp=0x26bffffea0 sp=0x26bffffea0 pc=0x7ff62a336d60

goroutine 52 gp=0x400072a700 m=10 mp=0x4000742008 [running]:
internal/filepathlite.1({0x40020ea7b0, 0x7})
        C:/Program Files/Go/src/internal/filepathlite/path_windows.go:204 +0x2b8 fp=0x4022d67380 sp=0x4022d67380 pc=0x7ff62a382af8
internal/filepathlite.VolumeName({0x40020ea7b0, 0x7})
        C:/Program Files/Go/src/internal/filepathlite/path.go:267 +0x24 fp=0x4022d673b0 sp=0x4022d67380 pc=0x7ff62a381e24
internal/filepathlite.Split({0x40020ea7b0, 0x7})
        C:/Program Files/Go/src/internal/filepathlite/path.go:206 +0x24 fp=0x4022d673d0 sp=0x4022d673b0 pc=0x7ff62a381b04
path/filepath.Split(...)
        C:/Program Files/Go/src/path/filepath/path.go:120
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:44 +0x28 fp=0x4022d67450 sp=0x4022d673d0 pc=0x7ff62b8c2968
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d674d0 sp=0x4022d67450 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d67550 sp=0x4022d674d0 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d675d0 sp=0x4022d67550 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d67650 sp=0x4022d675d0 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d676d0 sp=0x4022d67650 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d67750 sp=0x4022d676d0 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d677d0 sp=0x4022d67750 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d67850 sp=0x4022d677d0 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
        C:/Users/my_user/go/pkg/mod/sigs.k8s.io/kustomize/[email protected]/filesys/util.go:55 +0x168 fp=0x4022d678d0 sp=0x4022d67850 pc=0x7ff62b8c2aa8
sigs.k8s.io/kustomize/kyaml/filesys.PathSplit({0x40020ea7b0?, 0x7?})
...

Note: go version go1.24.5 windows/arm64

My proposal

I added a simple check to the existing condition in . This prevents issues when working with Windows systems.

@@ -49,7 +49,7 @@ func PathSplit(incoming string) []string {
                return []string{"", path}
        }
        dir = strings.TrimSuffix(dir, string(os.PathSeparator))
-       if dir == "" {
+       if dir == "" || path == "" {
                return []string{path}
        }
        return append(PathSplit(dir), path)

Why this works

The existing tests already pass with this change, which confirms this change does not impact existing unix support. It is aimed at ensuring consistent behaviour across operating systems without requiring more invasive changes.

Testing notes

The existing tests exclude Windows intentionally, and I wasn't sure if adapting them would be straightforward since proper testing needs to be done on a Windows host where resolves to the Windows-specific rune.

Any form of feedback is greatly appreciated.

Copy link

linux-foundation-easycla bot commented Jul 16, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: pcanilho
Once this PR has been reviewed and has the lgtm label, please assign koba1t for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 16, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @pcanilho!

It looks like this is your first PR to kubernetes-sigs/kustomize 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kustomize has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 16, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @pcanilho. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants