From 5144ba60f3a27b7c83bb0b4a730803bb4cc4ca1c Mon Sep 17 00:00:00 2001 From: Komposten Date: Fri, 12 Jul 2019 19:37:00 +0200 Subject: [PATCH] :bug: Fix ../ in paths displaying incorrectly Fixes #19 --- .../komposten/vivaldi/ui/InstructionTable.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/komposten/vivaldi/ui/InstructionTable.java b/src/main/java/komposten/vivaldi/ui/InstructionTable.java index cea5438..0462984 100644 --- a/src/main/java/komposten/vivaldi/ui/InstructionTable.java +++ b/src/main/java/komposten/vivaldi/ui/InstructionTable.java @@ -229,13 +229,21 @@ private Instruction fixInstructionPaths(Instruction original) String result = prefix + dir; int navUpIndex; - while ((navUpIndex = result.indexOf("../")) != -1) + int startIndex = 0; + while ((navUpIndex = result.indexOf("../", startIndex)) != -1) { - int previousSlash = result.lastIndexOf('/', navUpIndex); - - if (previousSlash != -1) + int previousSlash = result.lastIndexOf('/', navUpIndex-2); + + if (previousSlash != -1 && previousSlash >= startIndex) + { result = result.substring(0, previousSlash) + result.substring(navUpIndex + 2); + startIndex = 0; + } + else + { + startIndex = navUpIndex+1; + } } return new Instruction(src, result, original.excludeFromBrowserHtml);