From dbd00f9866726da4e1d4a4b5f64c378957c2c8b5 Mon Sep 17 00:00:00 2001 From: qespr Date: Fri, 7 Jul 2023 05:22:21 +0200 Subject: [PATCH] Fix incorrect Uri resolving when ".." is used instead of "../" Happens on sites like gemini://gemini.ctrl-c.club/~stack/gemlog/index.gmi --- app/src/main/java/corewala/buran/OppenURI.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/corewala/buran/OppenURI.kt b/app/src/main/java/corewala/buran/OppenURI.kt index db35c39..ec9f446 100644 --- a/app/src/main/java/corewala/buran/OppenURI.kt +++ b/app/src/main/java/corewala/buran/OppenURI.kt @@ -3,6 +3,7 @@ package corewala.buran import corewala.toURI const val GEMSCHEME = "gemini://" +const val PART_TRAVERSE = ".." const val TRAVERSE = "../" const val SOLIDUS = "/" const val DIREND = "/" @@ -41,10 +42,14 @@ class OppenURI constructor(private var ouri: String) { when { reference.startsWith(GEMSCHEME) -> set(reference) reference.startsWith(SOLIDUS) -> resolvedUri = "$scheme://$host$reference" - reference.startsWith(TRAVERSE) -> { - if(!ouri.endsWith(DIREND)) resolvedUri = ouri.removeFile() - val traversalCount = reference.split(TRAVERSE).size - 1 - resolvedUri = traverse(traversalCount) + reference.replace(TRAVERSE, "") + reference.startsWith(PART_TRAVERSE) -> { + val fixedReference = if (reference == PART_TRAVERSE) "$reference/" else reference + if (!ouri.endsWith(DIREND)) { + resolvedUri = ouri.removeFile() + } else { + val traversalCount = fixedReference.split(TRAVERSE).size - 1 + resolvedUri = traverse(traversalCount) + fixedReference.replace(TRAVERSE, "") + } } reference.startsWith(QUERY) -> { resolvedUri = if(reference.contains(QUERY)){