From 899bb290e912fb582b60f57e1bed0c53f2976770 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sat, 14 Sep 2024 14:30:56 +0300 Subject: [PATCH] validate absolute links conversion success --- .../tab/page/content/text/gemini/reader.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/app/browser/main/tab/page/content/text/gemini/reader.cpp b/src/app/browser/main/tab/page/content/text/gemini/reader.cpp index 63bee0d4..fa678d2a 100644 --- a/src/app/browser/main/tab/page/content/text/gemini/reader.cpp +++ b/src/app/browser/main/tab/page/content/text/gemini/reader.cpp @@ -252,6 +252,7 @@ Glib::ustring Reader::Make::link( const Glib::ustring & DATE, const Glib::ustring & ALT ) { + // Compose link description using optional date/alt values Glib::ustring description; if (!DATE.empty()) @@ -264,19 +265,22 @@ Glib::ustring Reader::Make::link( if (!ALT.empty()) { description.append( - description.empty() ? ALT : description + " " + ALT // append (to date) + description.empty() ? ALT : description + " " + ALT ); } + // Make relative links absolute using base given + const auto ABSOLUTE = g_uri_resolve_relative( + BASE.c_str(), + ADDRESS.c_str(), + G_URI_FLAGS_NONE, + NULL // GError * @TODO + ); + return Glib::ustring::sprintf( "%s\n", Glib::Markup::escape_text( - g_uri_resolve_relative( - BASE.c_str(), - ADDRESS.c_str(), - G_URI_FLAGS_NONE, - NULL // GError * @TODO - ) + ABSOLUTE == NULL ? ADDRESS : ABSOLUTE // @TODO exception? ), Glib::Markup::escape_text( ADDRESS