mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 19:26:17 +00:00
Make CameraX blocklist remote configurable.
This commit is contained in:
committed by
Cody Henthorne
parent
ace4157a14
commit
91d3f331e5
@@ -0,0 +1,23 @@
|
||||
package org.signal.core.util
|
||||
|
||||
/**
|
||||
* Treats the string as a serialized list of tokens and tells you if an item is present in the list.
|
||||
* In addition to exact matches, this handles wildcards at the end of an item.
|
||||
*
|
||||
* e.g. a,b,c*,d
|
||||
*/
|
||||
fun String.asListContains(item: String): Boolean {
|
||||
val items: List<String> = this
|
||||
.split(",")
|
||||
.map { it.trim() }
|
||||
.filter { it.isNotEmpty() }
|
||||
.toList()
|
||||
|
||||
val exactMatches = items.filter { it.last() != '*' }
|
||||
val prefixMatches = items.filter { it.last() == '*' }
|
||||
|
||||
return exactMatches.contains(item) ||
|
||||
prefixMatches
|
||||
.map { it.substring(0, it.length - 1) }
|
||||
.any { item.startsWith(it) }
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package org.signal.core.util
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.Parameterized
|
||||
|
||||
@RunWith(Parameterized::class)
|
||||
class StringExtensions_asListContains(
|
||||
private val model: String,
|
||||
private val serializedList: String,
|
||||
private val expected: Boolean
|
||||
) {
|
||||
|
||||
@Test
|
||||
fun testModelInList() {
|
||||
val actual = serializedList.asListContains(model)
|
||||
assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
@Parameterized.Parameters(name = "{index}: modelInList(model={0}, list={1})={2}")
|
||||
fun data(): List<Array<Any>> {
|
||||
return listOf<Array<Any>>(
|
||||
arrayOf("a", "a", true),
|
||||
arrayOf("a", "a,b", true),
|
||||
arrayOf("a", "c,a,b", true),
|
||||
arrayOf("ab", "a*", true),
|
||||
arrayOf("ab", "c,a*,b", true),
|
||||
arrayOf("abc", "c,ab*,b", true),
|
||||
|
||||
arrayOf("a", "b", false),
|
||||
arrayOf("a", "abc", false),
|
||||
arrayOf("b", "a*", false),
|
||||
).toList()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user