Skip to content

Commit

Permalink
🐛: fix missing username escape
Browse files Browse the repository at this point in the history
  • Loading branch information
Gamer92000 committed Feb 5, 2024
1 parent fb292d0 commit 9a2686e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 34 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
build
.vscode
.vscode
.vs

CMakePresets.json
CMakeUserPresets.json
75 changes: 61 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,53 @@
cmake_minimum_required(VERSION 3.10)

set(CMAKE_GENERATOR_TOOLSET "v140")
set(CMAKE_VS_PLATFORM_TOOLSET "v140")
# Use this to locate Qt5.12.3 on your development machine
# list(APPEND CMAKE_PREFIX_PATH "H:/Qt/5.12.3/msvc2017_64")
project("TelegramBridge")

set(CMAKE_CXX_STANDARD 20)

set(QT_VERSION 5)

if(MSVC)
set(CMAKE_GENERATOR_TOOLSET "v140")
set(CMAKE_VS_PLATFORM_TOOLSET "v140")

set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
set(CMAKE_C_FLAGS_DEBUG "/fsanitize=address")

foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()

set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2")

add_definitions(-D_USE_MATH_DEFINES)
else()
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -DNDEBUG")
endif()


set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

project("TelegramBridge")

message("Looking for Qt...")

find_package(Qt5 REQUIRED Widgets Network)
if (${Qt5_FOUND})
message("Found Qt " ${Qt5_VERSION})
else()
message("Couldn't find Qt")
endif()
#if(${QT_VERSION} EQUAL 5)
# list(APPEND CMAKE_PREFIX_PATH "H:/Qt/5.15.2/msvc2019_64")
#else()
# list(APPEND CMAKE_PREFIX_PATH "H:/Qt/6.6.0/msvc2019_64")
# add_definitions(-DQT_ADDITIONAL_PACKAGES_PREFIX_PATH="H:/Qt/6.6.0/msvc2019_64")
#endif()

find_package(Qt${QT_VERSION} REQUIRED Widgets Network)

include_directories("ts3client-pluginsdk/include")

Expand All @@ -32,8 +62,25 @@ set(sources

add_library(${CMAKE_PROJECT_NAME} SHARED ${sources})

if(MSVC)
target_compile_options(
${CMAKE_PROJECT_NAME}
PRIVATE
/MT
)
else()
target_compile_options(
${CMAKE_PROJECT_NAME}
PRIVATE
-fPIC
-static-libgcc
-static-libstdc++
)
endif()

target_link_libraries(
${CMAKE_PROJECT_NAME}
Qt5::Widgets
Qt5::Network
PUBLIC
Qt${QT_VERSION}::Widgets
Qt${QT_VERSION}::Network
)
24 changes: 5 additions & 19 deletions src/helper.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <QUrl>
#include <iostream>
#include "definitions.h"
#include "bbcode.hpp"
Expand Down Expand Up @@ -50,7 +51,7 @@ enum MessageType

static std::string prepareMessage(MessageType type, const char *source, const char *message)
{
std::string msg = "```%0A";
std::string msg = "`";

switch (type)
{
Expand All @@ -72,23 +73,8 @@ static std::string prepareMessage(MessageType type, const char *source, const ch
break;
}

msg += "%0A```%0A*_" + std::string(source) + "_*%0A" + parseBbcode(message);
msg += "`\n*_" + std::string(telegramEscape(source)) + "_*\n" + parseBbcode(message);

// url encode ? and & to avoid problems with the query string

size_t pos = 0;
while ((pos = msg.find("?", pos)) != std::string::npos)
{
msg.replace(pos, 1, "%3F");
pos += 3;
}

pos = 0;
while ((pos = msg.find("&", pos)) != std::string::npos)
{
msg.replace(pos, 1, "%26");
pos += 3;
}

return msg;
QByteArray encoded = QUrl::toPercentEncoding(QString::fromStdString( msg ), "", "");
return encoded.toStdString();
}

0 comments on commit 9a2686e

Please sign in to comment.