Skip to content

Conversation

@crStiv
Copy link

@crStiv crStiv commented Dec 21, 2025

What type of PR is this?

Bug fix
Feature
Documentation
Other

What does this PR do? Why is it needed?

Fixes a bug in RelativeTestTargetPath() where Bazel targets starting with : (e.g., ":bar") were incorrectly returned as-is instead of an empty string. The condition last > 0 missed the edge case when the colon is at position 0, which could cause invalid paths when used in path.Join() operations within TestDataPath().

The fix adds explicit handling for targets starting with :, returning an empty string to represent the current package, which is the correct behavior for such targets in Bazel.

Which issues(s) does this PR fix?

Fixes # (no issue filed - small bug fix)

Other notes for review

  • The change is minimal and only affects the edge case handling
  • All existing tests pass (go test -tags=bazel ./build/bazel/...)
  • The fix has been verified with test cases including ":bar", "//:bar", and standard formats like "//pkg/cmd/foo:bar"
  • This is an internal build tool fix and not user-facing, so changelog uses "Ignored" section

Acknowledgements

  • I have read CONTRIBUTING.md.
  • I have included a uniquely named changelog fragment file.
  • I have added a description with sufficient context for reviewers to understand this PR.
  • I have tested that my changes work as expected and I added a testing plan to the PR description (if applicable).

Fix edge case where targets starting with ':' (e.g., ":bar") were
incorrectly returned as-is instead of empty string. The condition
last > 0 missed the case when colon is at position 0, causing
invalid paths when used in path.Join operations.
Fix edge case in `RelativeTestTargetPath()` for Bazel targets starting with `:`.
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.

1 participant