From 52604d536a496a41d12597eca9084020704da94b Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 28 Jun 2018 13:34:51 +0200 Subject: [PATCH] Made URL-detecting regular expression better fixes #1 --- CMakeLists.txt | 2 +- src/url.cpp | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9e3150..6eb0178 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project (expandurl-mastodon - VERSION 0.9.9 + VERSION 0.9.10 LANGUAGES CXX ) diff --git a/src/url.cpp b/src/url.cpp index 7e36294..c97dc62 100644 --- a/src/url.cpp +++ b/src/url.cpp @@ -31,16 +31,20 @@ namespace curlopts = curlpp::options; const std::vector get_urls(const string &html) { - const std::regex re_url("href=\"([^\"]+)\" rel"); + const std::regex re_url("href=\\\\?\"([^\"\\\\]+)\\\\?\"([^>]+)"); std::smatch match; string buffer = html; std::vector v; while (std::regex_search(buffer, match, re_url)) { - string url = Easy::unescape_html(match[1].str()); - v.push_back(strip(expand(url))); - buffer = match.suffix().str(); + // Add URL to vector if it is not a mention.# + if (match[2].str().find("mention") == std::string::npos) + { + string url = Easy::unescape_html(match[1].str()); + v.push_back(strip(expand(url))); + buffer = match.suffix().str(); + } } return v;