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

RequestConfig.Execute corrupts base URL path tail. #160

Open
iamwavecut opened this issue Jan 8, 2025 · 0 comments · May be fixed by #161
Open

RequestConfig.Execute corrupts base URL path tail. #160

iamwavecut opened this issue Jan 8, 2025 · 0 comments · May be fixed by #161

Comments

@iamwavecut
Copy link

iamwavecut commented Jan 8, 2025

How to reproduce an isolated problem: https://go.dev/play/p/I0RUm0AIx_2

package main

import (
	"log"
	"net/url"
	"strings"
)

func main() {
	baseURLString := "http://base.url/some/path/v1"
	cfgRequestPath := "chat/completions"
	expectedURLString := "http://base.url/some/path/v1/chat/completions"

	baseURL, err := url.Parse(baseURLString)
	if err != nil {
		log.Fatal(err)
	}

	resultURL, err := baseURL.Parse(strings.TrimLeft(cfgRequestPath, "/"))
	if err != nil {
		log.Fatal(err)
	}

	log.Println("result URL == expected URL", resultURL.String() == expectedURLString)
	log.Println("expected URL", expectedURLString)
	log.Println("result URL", resultURL.String())
}

Actual result:

result URL == expected URL false
expected URL http://base.url/some/path/v1/chat/completions
result URL http://base.url/some/path/chat/completions

The URL construction logic is flawed, as it overwrites the last part of the BaseURL if it lacks a trailing slash.

Suggested fix:

Ensure that the BaseURL consistently ends with a trailing slash to prevent accidental truncation during path joining.

@iamwavecut iamwavecut linked a pull request Jan 8, 2025 that will close this issue
@iamwavecut iamwavecut changed the title RequestConfig.Execute rewrites base URL path tail. RequestConfig.Execute corrupts base URL path tail. Jan 8, 2025
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 a pull request may close this issue.

1 participant