From 601887655e7f128c1c938a24fc38d002a8aecb64 Mon Sep 17 00:00:00 2001 From: Mike Skec Date: Sat, 9 Jan 2021 13:12:58 +1100 Subject: Fixes a 'resource not found' bug When navigating to many sites, such as gemini://rawtext.club:1965/~sloum/geminilist and not having a trailing slash at the end of the URL, local links on the page would be incorrectly generated by QUrl::resolved, which would cause links to give a 'resource not found' error if they weren't at the root path of the server. This patch fixes this by making sure that all links given to the renderers include trailing slashes. --- src/browsertab.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'src/browsertab.cpp') diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 829216a..c330eb0 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -552,11 +552,20 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime) // Only cache text pages bool will_cache = true; + // We always give trailing slashes to the renderers + // since QUrl.resolve will not create absolute URLs properly + // without them. + QUrl cur_url = current_location; + if (cur_url.path().isEmpty()) + cur_url.setPath("/"); + else if (cur_url.path()[cur_url.path().length() - 1] != "/") + cur_url.setPath(cur_url.path() + "/"); + if (not plaintext_only and mime.is("text", "gemini")) { document = GeminiRenderer::render( data, - this->current_location, + cur_url, doc_style, this->outline, &this->page_title); @@ -565,7 +574,7 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime) { document = GophermapRenderer::render( data, - this->current_location, + cur_url, doc_style); } else if (not plaintext_only and mime.is("text","html")) @@ -611,7 +620,7 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime) document = GeminiRenderer::render( src.readAll(), - this->current_location, + cur_url, preview_style, this->outline); @@ -624,7 +633,7 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime) { document = MarkdownRenderer::render( data, - this->current_location, + cur_url, doc_style, this->outline, this->page_title); @@ -671,7 +680,7 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime) else if (mime.is("video") or mime.is("audio")) { doc_type = Media; - this->ui->media_browser->setMedia(data, this->current_location, mime.type); + this->ui->media_browser->setMedia(data, cur_url, mime.type); will_cache = false; } @@ -713,7 +722,7 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime) document = GeminiRenderer::render( page_data.toUtf8(), - this->current_location, + cur_url, doc_style, this->outline, &this->page_title); -- cgit v1.2.3