From 39b9f9e1b838d4abe2e69c54be605cbce82cf52b Mon Sep 17 00:00:00 2001 From: Alexandru Oprea Date: Wed, 16 Jul 2025 11:57:53 +0300 Subject: [PATCH] prevention of double slashes when building API URLs --- Source/TolgeeEditor/Private/STolgeeTranslationTab.cpp | 6 +++--- Source/TolgeeEditor/Private/TolgeeEditor.cpp | 2 +- .../Private/TolgeeEditorIntegrationSubsystem.cpp | 4 ++-- Source/TolgeeEditor/Private/TolgeeEditorSettings.cpp | 5 +++++ Source/TolgeeEditor/Public/TolgeeEditorSettings.h | 7 +++++++ .../TolgeeProviderLocalizationServiceOperations.cpp | 4 ++-- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Source/TolgeeEditor/Private/STolgeeTranslationTab.cpp b/Source/TolgeeEditor/Private/STolgeeTranslationTab.cpp index 685cc76..116737f 100644 --- a/Source/TolgeeEditor/Private/STolgeeTranslationTab.cpp +++ b/Source/TolgeeEditor/Private/STolgeeTranslationTab.cpp @@ -24,7 +24,7 @@ namespace void STolgeeTranslationTab::Construct(const FArguments& InArgs) { const UTolgeeEditorSettings* Settings = GetDefault(); - const FString LoginUrl = FString::Printf(TEXT("%s/login"), *Settings->ApiUrl); + const FString LoginUrl = FString::Printf(TEXT("%s/login"), *Settings->GetBaseUrl()); DrawHandle = UDebugDrawService::Register(TEXT("Game"), FDebugDrawDelegate::CreateSP(this, &STolgeeTranslationTab::DebugDrawCallback)); @@ -149,7 +149,7 @@ void STolgeeTranslationTab::ShowWidgetFor(const FString& TolgeeKeyId) const UTolgeeEditorSettings* Settings = GetDefault(); - const FString NewUrl = FString::Printf(TEXT("%s/projects/%s/translations/single?key=%s"), *Settings->ApiUrl, *ProjectId, *TolgeeKeyId); + const FString NewUrl = FString::Printf(TEXT("%s/projects/%s/translations/single?key=%s"), *Settings->GetBaseUrl(), *ProjectId, *TolgeeKeyId); const FString CurrentUrl = Browser->GetUrl(); if (NewUrl != CurrentUrl && Browser->IsLoaded()) @@ -167,7 +167,7 @@ FString STolgeeTranslationTab::FindProjectIdFor(const FString& TolgeeKeyId) cons TMap PendingRequests; for (const FString& ProjectId : Settings->ProjectIds) { - const FString RequestUrl = FString::Printf(TEXT("%s/v2/projects/%s/translations?filterKeyName=%s"), *Settings->ApiUrl, *ProjectId, *TolgeeKeyId); + const FString RequestUrl = FString::Printf(TEXT("%s/v2/projects/%s/translations?filterKeyName=%s"), *Settings->GetBaseUrl(), *ProjectId, *TolgeeKeyId); FHttpRequestRef HttpRequest = FHttpModule::Get().CreateRequest(); HttpRequest->SetVerb("GET"); diff --git a/Source/TolgeeEditor/Private/TolgeeEditor.cpp b/Source/TolgeeEditor/Private/TolgeeEditor.cpp index 42188f2..dabf2b6 100644 --- a/Source/TolgeeEditor/Private/TolgeeEditor.cpp +++ b/Source/TolgeeEditor/Private/TolgeeEditor.cpp @@ -122,7 +122,7 @@ void FTolgeeEditorModule::ExtendToolbar(FToolBarBuilder& Builder) []() { const UTolgeeEditorSettings* Settings = GetDefault(); - FPlatformProcess::LaunchURL(*Settings->ApiUrl, nullptr, nullptr); + FPlatformProcess::LaunchURL(*Settings->GetBaseUrl(), nullptr, nullptr); } )) ); diff --git a/Source/TolgeeEditor/Private/TolgeeEditorIntegrationSubsystem.cpp b/Source/TolgeeEditor/Private/TolgeeEditorIntegrationSubsystem.cpp index 550e0cb..267ce25 100644 --- a/Source/TolgeeEditor/Private/TolgeeEditorIntegrationSubsystem.cpp +++ b/Source/TolgeeEditor/Private/TolgeeEditorIntegrationSubsystem.cpp @@ -56,7 +56,7 @@ void UTolgeeEditorIntegrationSubsystem::FetchAllProjects() for (const FString& ProjectId : Settings->ProjectIds) { - const FString RequestUrl = FString::Printf(TEXT("%s/v2/projects/%s/export?format=PO"), *Settings->ApiUrl, *ProjectId); + const FString RequestUrl = FString::Printf(TEXT("%s/v2/projects/%s/export?format=PO"), *Settings->GetBaseUrl(), *ProjectId); UE_LOG(LogTolgee, Display, TEXT("Fetching localization data for project %s from Tolgee dashboard: %s"), *ProjectId, *RequestUrl); FetchFromDashboard(ProjectId, RequestUrl); } @@ -183,7 +183,7 @@ void UTolgeeEditorIntegrationSubsystem::FetchIfProjectsWereUpdated() for (const FString& ProjectId : Settings->ProjectIds) { - const FString RequestUrl = FString::Printf(TEXT("%s/v2/projects/%s/stats"), *Settings->ApiUrl, *ProjectId); + const FString RequestUrl = FString::Printf(TEXT("%s/v2/projects/%s/stats"), *Settings->GetBaseUrl(), *ProjectId); FHttpRequestRef HttpRequest = FHttpModule::Get().CreateRequest(); HttpRequest->SetVerb("GET"); diff --git a/Source/TolgeeEditor/Private/TolgeeEditorSettings.cpp b/Source/TolgeeEditor/Private/TolgeeEditorSettings.cpp index 53c0a65..528543f 100644 --- a/Source/TolgeeEditor/Private/TolgeeEditorSettings.cpp +++ b/Source/TolgeeEditor/Private/TolgeeEditorSettings.cpp @@ -2,6 +2,11 @@ #include "TolgeeEditorSettings.h" +FString UTolgeeEditorSettings::GetBaseUrl() const +{ + return ApiUrl.EndsWith(TEXT("/")) ? ApiUrl.LeftChop(1) : ApiUrl; +} + FName UTolgeeEditorSettings::GetCategoryName() const { return TEXT("Plugins"); diff --git a/Source/TolgeeEditor/Public/TolgeeEditorSettings.h b/Source/TolgeeEditor/Public/TolgeeEditorSettings.h index d9699db..7c339b4 100644 --- a/Source/TolgeeEditor/Public/TolgeeEditorSettings.h +++ b/Source/TolgeeEditor/Public/TolgeeEditorSettings.h @@ -64,6 +64,13 @@ class TOLGEEEDITOR_API UTolgeeEditorSettings : public UDeveloperSettings UPROPERTY(Config, EditAnywhere, Category = "Tolgee|Provider") TMap PerTargetSettings; + /** + * Returns the ApiUrl without a trailing slash. + * Use this when building API requests to avoid getting double slashes. + */ + FString GetBaseUrl() const; + +private: // ~ Begin UDeveloperSettings Interface virtual FName GetCategoryName() const override; // ~ End UDeveloperSettings Interface diff --git a/Source/TolgeeProvider/Private/TolgeeProviderLocalizationServiceOperations.cpp b/Source/TolgeeProvider/Private/TolgeeProviderLocalizationServiceOperations.cpp index 112b715..931fdb1 100644 --- a/Source/TolgeeProvider/Private/TolgeeProviderLocalizationServiceOperations.cpp +++ b/Source/TolgeeProvider/Private/TolgeeProviderLocalizationServiceOperations.cpp @@ -63,7 +63,7 @@ bool FTolgeeProviderUploadFileWorker::Execute(FTolgeeProviderLocalizationService const UTolgeeEditorSettings* ProviderSettings = GetDefault(); const FTolgeePerTargetSettings* ProjectSettings = ProviderSettings->PerTargetSettings.Find(TargetGuid); - const FString Url = FString::Printf(TEXT("%s/v2/projects/%s/single-step-import"), *ProviderSettings->ApiUrl, *ProjectSettings->ProjectId); + const FString Url = FString::Printf(TEXT("%s/v2/projects/%s/single-step-import"), *ProviderSettings->GetBaseUrl(), *ProjectSettings->ProjectId); FHttpRequestRef HttpRequest = FHttpModule::Get().CreateRequest(); HttpRequest->SetURL(Url); @@ -132,7 +132,7 @@ bool FTolgeeProviderDownloadFileWorker::Execute(FTolgeeProviderLocalizationServi const UTolgeeEditorSettings* ProviderSettings = GetDefault(); const FTolgeePerTargetSettings* ProjectSettings = ProviderSettings->PerTargetSettings.Find(TargetGuid); - const FString Url = FString::Printf(TEXT("%s/v2/projects/%s/export"), *ProviderSettings->ApiUrl, *ProjectSettings->ProjectId); + const FString Url = FString::Printf(TEXT("%s/v2/projects/%s/export"), *ProviderSettings->GetBaseUrl(), *ProjectSettings->ProjectId); FHttpRequestRef HttpRequest = FHttpModule::Get().CreateRequest(); HttpRequest->SetURL(Url);