Skip to content

Commit

Permalink
Merge pull request #766 from nextcloud/backport/762/stable-2.8
Browse files Browse the repository at this point in the history
[stable-2.8] SearchResultEntry: detect file results not from Files provider
  • Loading branch information
AlvaroBrey authored Nov 25, 2021
2 parents 99bcaa3 + dcd6a26 commit dc02fc2
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/main/java/com/owncloud/android/lib/common/SearchResultEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
package com.owncloud.android.lib.common

import android.net.UrlQuerySanitizer
import java.net.URL

/**
* One search result entry of an unified search
Expand All @@ -42,8 +41,14 @@ data class SearchResultEntry(
var attributes: Map<String, String> = emptyMap()
) {

companion object {
private const val PARAM_DIR = "dir"
private const val PARAM_FILE = "scrollto"
private const val DIR_ROOT = "/"
}

val isFile: Boolean
get() = fileId() != null
get() = fileId() != null || listOf(PARAM_DIR, PARAM_FILE).all { resourceUrl.contains(it) }

fun fileId(): String? {
return attributes["fileId"]
Expand All @@ -54,17 +59,20 @@ data class SearchResultEntry(
}

private fun parseRemotePath(): String {
val sanitizer = UrlQuerySanitizer()
sanitizer.allowUnregisteredParamaters = true
sanitizer.unregisteredParameterValueSanitizer = UrlQuerySanitizer.getAllButNulLegal()
val sanitizer = UrlQuerySanitizer().apply {
allowUnregisteredParamaters = true
unregisteredParameterValueSanitizer = UrlQuerySanitizer.getAllButNulLegal()
}

sanitizer.parseUrl(resourceUrl)
URL(resourceUrl).query?.let { sanitizer.parseQuery(it) }
val dir = if (sanitizer.getValue("dir") == "/") {
""
} else {
sanitizer.getValue("dir")

val dirParam = sanitizer.getValue(PARAM_DIR)
val dir = when (dirParam) {
DIR_ROOT -> ""
else -> dirParam
}
val file = sanitizer.getValue("scrollto")

val file = sanitizer.getValue(PARAM_FILE)

return "$dir/$file"
}
Expand Down

0 comments on commit dc02fc2

Please sign in to comment.