Describe the bug
The import-url command parses artifact URLs with strings.Split(f, ":").
This breaks normal URLs that contain additional colons, for example URLs with ports:
http://localhost:8080/spec.yaml:true
The current parsing logic reconstructs the URL from only the first two split parts:
f = urlAndMainAtrifactAndSecretName[0] + ":" + urlAndMainAtrifactAndSecretName[1]
So http://localhost:8080/spec.yaml:true becomes http://localhost, losing the port, path, and filename.
This affects import-url when using the optional :primary and secret suffixes.
Expected behavior
import-url should preserve the full URL, including scheme, host, port, path, query string, and fragment.
For example:
microcks import-url http://localhost:8080/spec.yaml:true
should send this URL to microcks:
http://localhost:8080/spec.yaml
with mainArtifact=true.
URLs without suffixes should also continue to work unchanged.
Actual behavior
The URL is split on every colon. For a URL like:
http://localhost:8080/spec.yaml:true
the parser splits it into parts like:
["http", "//localhost", "8080/spec.yaml", "true"]
Then it reconstructs only:
As a result, Microcks receives an incorrect artifact URL.
How to Reproduce?
Reproducer:
- Run
import-url with a URL that contains a port and the :primary suffix:
microcks import-url http://localhost:8080/spec.yaml:true \
--microcksURL=http://localhost:8080/api \
--keycloakClientId=<client-id> \
--keycloakClientSecret=<client-secret>
- Observe that the CLI parses the artifact URL incorrectly before calling DownloadArtifact.
Microcks version or git rev
Microcks CLI 1.0.2
Install method (docker-compose, helm chart, operator, docker-desktop extension,...)
built from source
Additional information
A possible fix is to avoid splitting the whole URL on every colon.
Options:
- parse suffixes from the right side only, for example with
strings.LastIndex;
- use URL-aware parsing and only treat trailing
:true, :false, and optional secret values as CLI metadata;
- add focused unit tests for URLs with ports, paths, query strings, and suffixes.
Related code:
urlAndMainAtrifactAndSecretName := strings.Split(f, ":")
n := len(urlAndMainAtrifactAndSecretName)
f = urlAndMainAtrifactAndSecretName[0] + ":" + urlAndMainAtrifactAndSecretName[1]
Describe the bug
The
import-urlcommand parses artifact URLs withstrings.Split(f, ":").This breaks normal URLs that contain additional colons, for example URLs with ports:
The current parsing logic reconstructs the URL from only the first two split parts:
f = urlAndMainAtrifactAndSecretName[0] + ":" + urlAndMainAtrifactAndSecretName[1]So http://localhost:8080/spec.yaml:true becomes http://localhost, losing the port, path, and filename.
This affects import-url when using the optional :primary and secret suffixes.
Expected behavior
import-urlshould preserve the full URL, including scheme, host, port, path, query string, and fragment.For example:
should send this URL to microcks:
with mainArtifact=true.
URLs without suffixes should also continue to work unchanged.
Actual behavior
The URL is split on every colon. For a URL like:
the parser splits it into parts like:
Then it reconstructs only:
As a result, Microcks receives an incorrect artifact URL.
How to Reproduce?
Reproducer:
import-urlwith a URL that contains a port and the:primarysuffix:Microcks version or git rev
Microcks CLI 1.0.2
Install method (
docker-compose,helm chart,operator,docker-desktop extension,...)built from source
Additional information
A possible fix is to avoid splitting the whole URL on every colon.
Options:
strings.LastIndex;:true,:false, and optional secret values as CLI metadata;Related code: