Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape Raw Brackets In Request URLs #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Ameston
Copy link

@Ameston Ameston commented Jan 23, 2025

Malformed HTTP requests that leverage raw brackets in the request URL are not handled correctly by the library. For example:

req1, err := http.NewRequest("GET", "https://example.com/[", nil)
	if err != nil {
		log.Fatalf("Failed to create request: %v", err)
	}
	req1.Header.Add("User-Agent", "test-agent")
	req1.Header.Add("Accept", "*/*")
	
	command1, err := http2curl.GetCurlCommand(req1)
	if err != nil {
		log.Fatalf("Failed to generate curl command: %v", err)
	}
	fmt.Printf("Test 1 - Basic request with brackets:\n%s\n\n", command1)

This results in the following cURL command:

curl -k -X 'GET' -H 'Accept: */*' -H 'User-Agent: test-agent' 'https://example.com/[' --compressed

Which results in a syntax error when run:

curl: (3) bad range specification in URL position 22:
https://example.com/[

This PR resolves this issue by escaping brackets in the URLs of HTTP requests.

@Ameston Ameston requested a review from moul as a code owner January 23, 2025 23:10
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