fix(import): preserve paths containing colons when parsing primary su…#353
Open
hazelmayank wants to merge 1 commit into
Open
fix(import): preserve paths containing colons when parsing primary su…#353hazelmayank wants to merge 1 commit into
hazelmayank wants to merge 1 commit into
Conversation
…ffix Signed-off-by: hazelmayank <mayankjeefinal@gmail.com>
|
the
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
microcks importpreviously parsed the optional:true/:falsesuffix withstrings.Split(input, ":")[0], which splits on the first colon. Any input containing more than one colon — including Windows-absolute paths such asC:\Temp\api.yaml— had its path truncated to the part before the first colon, and the rest was passed tostrconv.ParseBool. The eventual upload failed withopen 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/:falsesuffix continues to work exactly as before.Why
microcks importtoday.open C: no such file or directory) gives no hint that the parser truncated the path../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
parseImportEntry(input string) (string, bool)incmd/import.go.:and only treats it asmainArtifactwhenstrconv.ParseBoolsucceeds; otherwise the entire input is treated as the path withmainArtifact = true.if strings.Contains(f, ":") { ... }block in the import loop with a single call to the helper.Cannot parse '...' as Boolwarning, because the new logic treats a non-bool trailing segment as part of the path rather than a parse failure.cmd/import_test.gowith table-driven cases for the parser.Test plan
go build ./...go vet ./...gofmt -l cmd/import.go cmd/import_test.go— no outputgo test ./cmd/... -run TestParseImportEntry -v— all table rows passgo test ./...— full sweep passesgo test ./cmd/... -count=3— passes (no state leakage)microcks import C:\Temp\api.yamlno longer fails withopen C: no such file or directory./api.yaml,./api.yaml:true,./api.yaml:false,./api.yaml:1all parse as beforeTest cases covered
The table-driven test exercises:
./api.yaml./api.yamltrue./api.yaml:true./api.yamltrue./api.yaml:false./api.yamlfalse./api.yaml:TRUE./api.yamltrue./api.yaml:0./api.yamlfalseC:\Temp\api.yamlC:\Temp\api.yamltrueC:\Temp\api.yaml:falseC:\Temp\api.yamlfalseC:\Temp\api.yaml:trueC:\Temp\api.yamltruepath:with:colon.yamlpath:with:colon.yamltruepath:with:colon.yaml:falsepath:with:colon.yamlfalse./api.yaml:notabool./api.yaml:notabooltrueFiles changed
cmd/import.go— parser refactored;strconvimport retained forParseBool.cmd/import_test.go— new file; first test in this package's import-command path.Notes
cmd/importURL.gofor 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.Closes #352