Stripping more tracking parameters; Added AMP subdomain removal

This commit is contained in:
tastytea 2018-05-18 13:27:12 +02:00
parent 44f1692e80
commit 6da8c1ca07
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
2 changed files with 20 additions and 3 deletions

View File

@ -1,6 +1,6 @@
cmake_minimum_required (VERSION 3.7)
project (expandurl-mastodon
VERSION 0.3.0
VERSION 0.3.1
LANGUAGES CXX
)

View File

@ -17,6 +17,8 @@
#include <iostream>
#include <sstream>
#include <regex>
#include <array>
#include <utility>
#include <curlpp/cURLpp.hpp>
#include <curlpp/Options.hpp>
#include <curlpp/Infos.hpp>
@ -75,6 +77,21 @@ const string expand(const string &url)
const string strip(const string &url)
{
const std::regex re("[\\?&]utm_[^&]+");
return std::regex_replace(url, re, "");
using replace_pair = std::pair<const std::regex, const std::string>;
string newurl = url;
const std::array<const replace_pair, 4> replace_array =
{{
{ std::regex("[\\?&]utm_[^&]+"), "" },
{ std::regex("[\\?&]wtmc=[^&]+"), "" },
{ std::regex("[\\?&]__twitter_impression=[^&]+"), "" },
{ std::regex("//amp\\."), "//" }
}};
for (const replace_pair &pair : replace_array)
{
newurl = std::regex_replace(newurl, pair.first, pair.second);
}
return newurl;
}