Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-2.8] SearchResultEntry: detect file results not from Files provider #766

Merged
merged 1 commit into from
Nov 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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