From 6ed6ff1a3645958dd5309a3b7a8165ae38bb8d0d Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 10 Aug 2023 21:03:25 +0200 Subject: [PATCH] Ensure base path always starts and ends with / The base path is an absolute path, so it should always start with /. Whenever it is used, it must also always be followed by at least one /, so baking that into the value makes sense. Finally, we can now deduplicate the / in case the base path is the root. --- src/config.rs | 18 ++++++++++-------- templates/base.html | 13 +++++-------- templates/index.html | 4 ++-- templates/queue_table.html | 2 +- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/config.rs b/src/config.rs index 5c90357..730044f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,7 +22,7 @@ mod default { use std::{net::SocketAddr, time::Duration}; pub fn web_base() -> String { - "".to_string() + "/".to_string() } pub fn web_address() -> SocketAddr { @@ -138,13 +138,14 @@ impl ConfigFile { } fn web_base(&self) -> String { - self.web - .base - .strip_prefix('/') - .unwrap_or(&self.web.base) - .strip_suffix('/') - .unwrap_or(&self.web.base) - .to_string() + let mut base = self.web.base.clone(); + if !base.starts_with('/') { + base.insert(0, '/'); + } + if !base.ends_with('/') { + base.push('/'); + } + base } fn web_runner_token(&self) -> String { @@ -204,6 +205,7 @@ pub struct RunnerServerConfig { } pub struct Config { + /// Always starts and ends with a `/`. pub web_base: String, pub web_address: SocketAddr, pub web_runner_token: String, diff --git a/templates/base.html b/templates/base.html index e8512f7..5bf99cb 100644 --- a/templates/base.html +++ b/templates/base.html @@ -5,20 +5,17 @@ {% block title %}{% endblock %} - {{ base.repo_name }} - - + + {% block head %}{% endblock %} diff --git a/templates/index.html b/templates/index.html index 75f0891..0403805 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,7 +11,7 @@ {% for ref in tracked_refs %}
{{ ref.name }}
- + {% call util::commit_short(ref.short, ref.reachable) %}
@@ -24,7 +24,7 @@ {% for ref in untracked_refs %}
{{ ref.name }}
- + {% call util::commit_short(ref.short, ref.reachable) %}
diff --git a/templates/queue_table.html b/templates/queue_table.html index 0b182a8..ea90828 100644 --- a/templates/queue_table.html +++ b/templates/queue_table.html @@ -12,7 +12,7 @@ {% for task in tasks %} - + {% call util::commit_short(task.short, task.reachable) %}