From 0748ae833337c698263cd6cb3176ec19d9ddbd25 Mon Sep 17 00:00:00 2001 From: Bastien Abadie Date: Wed, 20 Nov 2019 17:42:29 +0100 Subject: [PATCH 1/2] frontend: Fix file name rendering when dir ends with /, fixes #290 --- frontend/src/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frontend/src/index.js b/frontend/src/index.js index 1c06bee32..dd91d37da 100644 --- a/frontend/src/index.js +++ b/frontend/src/index.js @@ -124,7 +124,13 @@ async function showDirectory(dir, revision, files) { revision: revision || REV_LATEST, file_name() { // Build filename relative to current dir - return dir ? this.path.substring(dir.length + 1) : this.path; + if (dir) { + // Remove extra / only when present + const offset = dir.substring(dir.length - 1) === "/" ? 0 : 1; + return this.path.substring(dir.length + offset); + } + + return this.path; } }; render("file_browser", context, "output"); From cdca59bc22a8b369066bd873750b2dfac2204d29 Mon Sep 17 00:00:00 2001 From: Bastien Abadie Date: Wed, 20 Nov 2019 17:55:16 +0100 Subject: [PATCH 2/2] I am dumb. --- frontend/src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/index.js b/frontend/src/index.js index dd91d37da..94b527f64 100644 --- a/frontend/src/index.js +++ b/frontend/src/index.js @@ -126,7 +126,7 @@ async function showDirectory(dir, revision, files) { // Build filename relative to current dir if (dir) { // Remove extra / only when present - const offset = dir.substring(dir.length - 1) === "/" ? 0 : 1; + const offset = dir[dir.length - 1] === "/" ? 0 : 1; return this.path.substring(dir.length + offset); }