diff options
author | Fabian Henneke <fabian@henneke.me> | 2020-04-15 19:09:51 +0200 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2020-04-15 22:47:41 +0530 |
commit | 2a6326ec0ea04ceade7e56749b4cd09f810a34a7 (patch) | |
tree | 7014bb293c020b1788812c5e2a93d23a80ebd074 /app/src/main/java/com | |
parent | 7cd6f1d1cf78f60cf187d23469934c83915c778d (diff) |
Address review comments
Diffstat (limited to 'app/src/main/java/com')
-rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/SearchableRepositoryViewModel.kt | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/SearchableRepositoryViewModel.kt b/app/src/main/java/com/zeapo/pwdstore/SearchableRepositoryViewModel.kt index 1604cb66..b7f7ee61 100644 --- a/app/src/main/java/com/zeapo/pwdstore/SearchableRepositoryViewModel.kt +++ b/app/src/main/java/com/zeapo/pwdstore/SearchableRepositoryViewModel.kt @@ -126,28 +126,6 @@ enum class ListMode { @FlowPreview class SearchableRepositoryViewModel(application: Application) : AndroidViewModel(application) { - companion object { - - fun generateStrictDomainRegex(domain: String): Regex? { - // Valid domains do not contain path separators. - if (domain.contains('/')) - return null - // Matches the start of a path component, which is either the start of the - // string or a path separator. - val prefix = """(?:^|/)""" - val escapedFilter = Regex.escape(domain.replace("/", "")) - // Matches either the filter literally or a strict subdomain of the filter term. - // We allow a lot of freedom in what a subdomain is, as long as it is not an - // email address. - val subdomain = """(?:(?:[^/@]+\.)?$escapedFilter)""" - // Matches the end of a path component, which is either the literal ".gpg" or a - // path separator. - val suffix = """(?:\.gpg|/)""" - // Match any relative path with a component that is a subdomain of the filter. - return Regex(prefix + subdomain + suffix) - } - } - private var _updateCounter = 0 private val updateCounter: Int get() = _updateCounter @@ -371,6 +349,28 @@ class SearchableRepositoryViewModel(application: Application) : AndroidViewModel forceUpdateOnNextSearchAction() searchAction.postValue(updateSearchAction(searchAction.value!!)) } + + companion object { + + fun generateStrictDomainRegex(domain: String): Regex? { + // Valid domains do not contain path separators. + if (domain.contains('/')) + return null + // Matches the start of a path component, which is either the start of the + // string or a path separator. + val prefix = """(?:^|/)""" + val escapedFilter = Regex.escape(domain.replace("/", "")) + // Matches either the filter literally or a strict subdomain of the filter term. + // We allow a lot of freedom in what a subdomain is, as long as it is not an + // email address. + val subdomain = """(?:(?:[^/@]+\.)?$escapedFilter)""" + // Matches the end of a path component, which is either the literal ".gpg" or a + // path separator. + val suffix = """(?:\.gpg|/)""" + // Match any relative path with a component that is a subdomain of the filter. + return Regex(prefix + subdomain + suffix) + } + } } private object PasswordItemDiffCallback : DiffUtil.ItemCallback<PasswordItem>() { |