Skip to content

Conversation

@bc-lee
Copy link

@bc-lee bc-lee commented Nov 17, 2025

Previously, any provided GitHub URL was treated as a GitHub Enterprise Server (GHES) instance when selecting the API endpoint. This assumption was incorrect because the URL can also be for GitHub.com (e.g., https://github.com), which led to using the wrong API endpoint.

This commit adds a function to extract the host from a URL. This is used to differentiate between GitHub.com and GHES instances to select the correct API endpoint.

Fixes microsoft/vcpkg#48347

Previously, any provided GitHub URL was treated as a GitHub Enterprise
Server (GHES) instance when selecting the API endpoint. This assumption was
incorrect because the URL can also be for GitHub.com (e.g., https://github.com),
which led to using the wrong API endpoint.

This commit adds a function to extract the host from a URL. This is used to
differentiate between GitHub.com and GHES instances to select the correct
API endpoint.
}

// Extracts the host part from a URL string.
std::string extract_host(StringView url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thing needs unit tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL parsing is an insanely complicated problem; a parsing function that just returns whether we get github.com or not may be easier. Otherwise we may want to look at using trurl.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review. I’ll revisit this once the curl library integration has been re-landed.

Comment on lines +54 to +55
const char* at_sign = Strings::find_first_of(url, "@");
size_t at_pos = at_sign[0] == '\0' ? std::string::npos : static_cast<size_t>(at_sign - url.data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is undefined behavior: you can't dereference the returned iterator if there was no match. And there is no requirement that there is a \0 after a StringView

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto several times below

}

// Remove userinfo if present (e.g., user:pass@host)
const char* at_sign = Strings::find_first_of(url, "@");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems little reason to use find_first_of when there is only one char you're looking for?

@bc-lee bc-lee marked this pull request as draft November 25, 2025 02:37
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.

Dependency graph submission failed

2 participants