Skip to content

fix(import): preserve paths containing colons when parsing primary su…#353

Open
hazelmayank wants to merge 1 commit into
microcks:masterfrom
hazelmayank:fix/import-windows-path-parser
Open

fix(import): preserve paths containing colons when parsing primary su…#353
hazelmayank wants to merge 1 commit into
microcks:masterfrom
hazelmayank:fix/import-windows-path-parser

Conversation

@hazelmayank
Copy link
Copy Markdown
Contributor

@hazelmayank hazelmayank commented May 9, 2026

Summary

microcks import previously parsed the optional :true / :false suffix with strings.Split(input, ":")[0], which splits on the first colon. Any input containing more than one colon — including Windows-absolute paths such as C:\Temp\api.yaml — had its path truncated to the part before the first colon, and the rest was passed to strconv.ParseBool. The eventual upload failed with open C: no such file or directory, with no hint that the parser had silently eaten the path.

This PR fixes the parser to detect the boolean suffix from the right using strings.LastIndex + strconv.ParseBool, so paths containing colons (Windows-absolute paths, paths with multiple colons) are preserved while the documented :true / :false suffix continues to work exactly as before.


Why

  • Windows users are blocked from using absolute paths with microcks import today.
  • The failure mode (open C: no such file or directory) gives no hint that the parser truncated the path.
  • All currently-documented inputs (./api.yaml, ./api.yaml:true, ./api.yaml:false, ./api.yaml:1, …) keep working identically after the fix — this is a strict superset of previous behavior.

What changed

  • Extracted a small pure helper parseImportEntry(input string) (string, bool) in cmd/import.go.
  • The helper inspects the substring after the last : and only treats it as mainArtifact when strconv.ParseBool succeeds; otherwise the entire input is treated as the path with mainArtifact = true.
  • Replaced the inline if strings.Contains(f, ":") { ... } block in the import loop with a single call to the helper.
  • Removed the now-redundant Cannot parse '...' as Bool warning, because the new logic treats a non-bool trailing segment as part of the path rather than a parse failure.
  • Added a new test file cmd/import_test.go with table-driven cases for the parser.

Test plan

  • go build ./...
  • go vet ./...
  • gofmt -l cmd/import.go cmd/import_test.go — no output
  • go test ./cmd/... -run TestParseImportEntry -v — all table rows pass
  • go test ./... — full sweep passes
  • go test ./cmd/... -count=3 — passes (no state leakage)
  • Manually verified on Windows: microcks import C:\Temp\api.yaml no longer fails with open C: no such file or directory
  • Manually verified that ./api.yaml, ./api.yaml:true, ./api.yaml:false, ./api.yaml:1 all parse as before

Test cases covered

The table-driven test exercises:

Input Path mainArtifact
./api.yaml ./api.yaml true
./api.yaml:true ./api.yaml true
./api.yaml:false ./api.yaml false
./api.yaml:TRUE ./api.yaml true
./api.yaml:0 ./api.yaml false
C:\Temp\api.yaml C:\Temp\api.yaml true
C:\Temp\api.yaml:false C:\Temp\api.yaml false
C:\Temp\api.yaml:true C:\Temp\api.yaml true
path:with:colon.yaml path:with:colon.yaml true
path:with:colon.yaml:false path:with:colon.yaml false
./api.yaml:notabool ./api.yaml:notabool true

Files changed

  • cmd/import.go — parser refactored; strconv import retained for ParseBool.
  • cmd/import_test.go — new file; first test in this package's import-command path.

Notes

  • No flag changes; no behavior change for currently-working inputs.
  • A similar bug exists in cmd/importURL.go for URLs that include a port (e.g. https://localhost:8080/api.yaml). It is intentionally left out of this PR to keep scope tight; happy to send a follow-up if maintainers prefer that shape.
  • This is one of my early contributions to the repo; I am still learning Go and welcome any feedback on idiom or structure.

Closes #352

…ffix

Signed-off-by: hazelmayank <mayankjeefinal@gmail.com>
@Harishrs2006
Copy link
Copy Markdown

the LastIndex + ParseBool approach is the right way to handle this.

cmd/importURL.go has the same colon-splitting bug and isn't touched by this PR. Also, PR #291 is already open and covers both import.go and importURL.go together

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.

microcks import truncates Windows absolute paths when parsing :primary suffix

2 participants