Skip to content

Commit

Permalink
Filter URLs in requestBrowserDomains with incorrect symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Dec 3, 2023
1 parent 846b10c commit 44c4540
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaBrowserDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "StdInc.h"
#include "lua/CLuaFunctionParser.h"
#include <regex>

void CLuaBrowserDefs::LoadFunctions()
{
Expand Down Expand Up @@ -182,8 +183,12 @@ int CLuaBrowserDefs::RequestBrowserDomains(lua_State* luaVM)

if (!argStream.HasErrors())
{
// Remove empty URLs
pages.erase(std::remove_if(pages.begin(), pages.end(), [](const auto& url) { return url.empty(); }), pages.end());
// Remove empty and invalid URLs
std::regex invalidSynmbolsRegex("[^A-Za-z0-9\-._~!#$&'()*+,;=:@\/?%]");

pages.erase(std::remove_if(pages.begin(), pages.end(),
[&invalidSynmbolsRegex](const auto& url) { return url.empty() || std::regex_search(url, invalidSynmbolsRegex); }),
pages.end());

// Convert to domains if we got a list of URLs
if (bIsURL)
Expand Down

0 comments on commit 44c4540

Please sign in to comment.