diff options
| author | Mike Skec <skec@protonmail.ch> | 2021-01-09 13:12:58 +1100 |
|---|---|---|
| committer | Felix Queißner <felix@ib-queissner.de> | 2021-01-10 13:40:46 +0100 |
| commit | 601887655e7f128c1c938a24fc38d002a8aecb64 (patch) | |
| tree | 864c4e1edf35489418a2d8f7108832c4501e972c /src/browsertab.cpp | |
| parent | 9fffc1ca149c832dcf721d0de38248bb16528b23 (diff) | |
| download | kristall-601887655e7f128c1c938a24fc38d002a8aecb64.tar.gz | |
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.
Diffstat (limited to 'src/browsertab.cpp')
| -rw-r--r-- | src/browsertab.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
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); |
