Skip to content

Commit

Permalink
Strip non ASCII characters from git user agent
Browse files Browse the repository at this point in the history
Github decided to simply break any request containing non ASCII characters, thus making cloning not work, even if this could be a temporairy thing, make the change regardless as in the end it should not have any difference
  • Loading branch information
edo9300 committed Mar 26, 2023
1 parent 8b1bfbc commit 9a4c0b1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gframe/client_updater.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "client_updater.h"
#ifdef UPDATE_URL
#include "client_updater.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
Expand Down
2 changes: 1 addition & 1 deletion gframe/repo_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ RepoManager::RepoManager() {
else
git_libgit2_opts(GIT_OPT_SET_SSL_CERT_LOCATIONS, "SYSTEM", "");
#endif
git_libgit2_opts(GIT_OPT_SET_USER_AGENT, ygo::Utils::GetUserAgent().data());
git_libgit2_opts(GIT_OPT_SET_USER_AGENT, ygo::Utils::GetASCIIUserAgent().data());
#if (LIBGIT2_VER_MAJOR>0 && LIBGIT2_VER_MINOR>=3) || LIBGIT2_VER_MAJOR>1
// disable option introduced with https://github.com/libgit2/libgit2/pull/6266
// due how this got backported in older libgitversion as well, and in case
Expand Down
12 changes: 11 additions & 1 deletion gframe/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,17 @@ namespace ygo {
}
const std::string& Utils::GetUserAgent() {
static const std::string agent = epro::format("EDOPro-" OSSTRING "-" STR(EDOPRO_VERSION_MAJOR) "." STR(EDOPRO_VERSION_MINOR) "." STR(EDOPRO_VERSION_PATCH)" {}",
ygo::Utils::OSOperator->getOperatingSystemVersion());
Utils::OSOperator->getOperatingSystemVersion());
return agent;
}
const std::string& Utils::GetASCIIUserAgent() {
static const std::string agent = [] {
auto agent = GetUserAgent();
agent.erase(std::remove_if(agent.begin(), agent.end(),
[](char c){ return (static_cast<unsigned>(c) & 0x80) != 0; }),
agent.end());
return agent;
}();
return agent;
}
epro::path_string Utils::GetAbsolutePath(epro::path_stringview path) {
Expand Down
2 changes: 2 additions & 0 deletions gframe/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ namespace ygo {

static const std::string& GetUserAgent();

static const std::string& GetASCIIUserAgent();

static epro::path_string GetAbsolutePath(epro::path_stringview path);

template<typename T>
Expand Down

0 comments on commit 9a4c0b1

Please sign in to comment.