1
0
Fork 0
mirror of https://github.com/Corewala/Buran synced 2024-12-22 07:42:43 +00:00

Made relative query strings work in accordance with the URL spec

This commit is contained in:
Corewala 2022-08-04 12:17:20 -04:00
parent f89f41ae14
commit eee109bb28

View file

@ -6,6 +6,7 @@ const val GEMSCHEME = "gemini://"
const val TRAVERSE = "../" const val TRAVERSE = "../"
const val SOLIDUS = "/" const val SOLIDUS = "/"
const val DIREND = "/" const val DIREND = "/"
const val QUERY = "?"
/** /**
* *
@ -44,9 +45,18 @@ class OppenURI constructor(private var ouri: String) {
val traversalCount = reference.split(TRAVERSE).size - 1 val traversalCount = reference.split(TRAVERSE).size - 1
ouri = traverse(traversalCount) + reference.replace(TRAVERSE, "") ouri = traverse(traversalCount) + reference.replace(TRAVERSE, "")
} }
reference.startsWith(QUERY) -> {
ouri = if(reference.contains(QUERY)){
ouri.substringBefore(QUERY) + reference
}else{
ouri + reference
}
}
else -> { else -> {
ouri = when { ouri = when {
ouri.endsWith(DIREND) -> "${ouri}$reference" ouri.endsWith(DIREND) -> {
"${ouri}$reference"
}
else -> "${ouri.substring(0, ouri.lastIndexOf("/"))}/$reference" else -> "${ouri.substring(0, ouri.lastIndexOf("/"))}/$reference"
} }
} }