fix (cmd) : URL Port Corrupts Input in Import-URL Command#465
Open
aniket866 wants to merge 1 commit into
Open
Conversation
Signed-off-by: aniket866 <iamaniketkumarmaner@gmail.com>
71d9bc2 to
3fb94dc
Compare
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.
Description
The
import-urlcommand parses arguments formatted asurl:primary:secret. It usesstrings.Split(f, ":")and reconstructs the URL by concatenating the first two elements. If the URL contains a port number (e.g.http://localhost:8585/spec.yaml), the split splits it into["http", "//localhost", "8585/spec.yaml"]. The code then drops the port and path, changing the URL tohttp://localhost.Reason Why It Is Valid
It breaks importing artifacts from local test instances or any custom web server that runs on a non-default port (containing a colon).
Bug Simulation Workflow
graph TD A["User runs: microcks import-url http://localhost:8585/api.yaml"] --> B["Split by ':' produces http, //localhost, 8585/api.yaml"] B --> C["Reconstruction: urlAndMainAtrifactAndSecretName[0] + ':' + urlAndMainAtrifactAndSecretName[1]"] C --> D["Resulting URL is http://localhost"] D --> E["API import request sent to http://localhost instead of http://localhost:8585/api.yaml"]after fix:
importURL.goReplace the simple : splitting logic with a more robust parser that checks segments from the right end of the string to identify the optional main and secret parameters.
importURL_test.goAdd unit tests to verify the parsing logic for various URL combinations, including:
Closes #463
@lbroudoux @Harsh4902
do checkout whenever you get time