From 30ddf1e9b2e1ddb3f74cfe21b302f560164becf1 Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 13 Aug 2023 19:57:23 +0200 Subject: [PATCH] Ensure web_base does not end in / --- src/config.rs | 24 ++++++++++++++---------- src/server/web/link.rs | 6 +++--- templates/base.html | 10 +++++----- templates/queue.html | 2 +- 4 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/config.rs b/src/config.rs index d1e909e..bd107de 100644 --- a/src/config.rs +++ b/src/config.rs @@ -146,14 +146,11 @@ impl ConfigFile { } fn web_base(&self) -> String { - let mut base = self.web.base.clone(); - if !base.starts_with('/') { - base.insert(0, '/'); - } - if !base.ends_with('/') { - base.push('/'); - } - base + self.web + .base + .strip_suffix('/') + .unwrap_or(&self.web.base) + .to_string() } fn web_worker_token(&self) -> String { @@ -210,14 +207,21 @@ impl ConfigFile { // TODO Url functions #[derive(Clone)] pub struct WorkerServerConfig { - /// Never ends with a `/`. + /// Always ends without a `/`. + /// + /// This means that you can prefix the url onto an absolute path and get a + /// correct url. pub url: String, pub token: String, } #[derive(Clone)] pub struct Config { - /// Always starts and ends with a `/`. + /// Always ends without a `/` (prioritizing the latter). + /// + /// This means that you can prefix the base onto an absolute path and get + /// another absolute path. You could also use an url here if you have a + /// weird reason to do so. pub web_base: String, pub web_address: SocketAddr, pub web_worker_token: String, diff --git a/src/server/web/link.rs b/src/server/web/link.rs index d9d1f05..c63bbce 100644 --- a/src/server/web/link.rs +++ b/src/server/web/link.rs @@ -9,7 +9,7 @@ use super::Base; ext = "html", source = "\ {% import \"util.html\" as util %} - {{ short }} @@ -38,7 +38,7 @@ impl CommitLink { #[template( ext = "html", source = "\ - + Run of {{ short }} " @@ -62,7 +62,7 @@ impl RunLink { #[template( ext = "html", source = "\ - + {{ name }} " diff --git a/templates/base.html b/templates/base.html index 5bf99cb..fd84699 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,17 +5,17 @@ {% block title %}{% endblock %} - {{ base.repo_name }} - - + + {% block head %}{% endblock %} diff --git a/templates/queue.html b/templates/queue.html index fb164f7..a09fc85 100644 --- a/templates/queue.html +++ b/templates/queue.html @@ -3,7 +3,7 @@ {% block title %}queue ({{ inner.tasks.len() }}){% endblock %} {% block head %} - + {% endblock %} {% block body %}