diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 4efbfe1..2d4b36c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -24,8 +24,8 @@ android { minSdk = 29 targetSdk = 34 - versionCode = 1708536354 - versionName = "0.25.2-beta" + versionCode = 1708536355 + versionName = "0.25.3-beta" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/java/f/cking/software/domain/interactor/filterchecker/FilterCheckerImpl.kt b/app/src/main/java/f/cking/software/domain/interactor/filterchecker/FilterCheckerImpl.kt index a24435b..b457d3d 100644 --- a/app/src/main/java/f/cking/software/domain/interactor/filterchecker/FilterCheckerImpl.kt +++ b/app/src/main/java/f/cking/software/domain/interactor/filterchecker/FilterCheckerImpl.kt @@ -1,5 +1,6 @@ package f.cking.software.domain.interactor.filterchecker +import f.cking.software.checkRegexSafe import f.cking.software.data.helpers.PowerModeHelper import f.cking.software.data.repo.DevicesRepository import f.cking.software.domain.interactor.CheckDeviceIsFollowingInteractor @@ -26,12 +27,12 @@ class FilterCheckerImpl( device.firstDetectTimeMs in filter.from..filter.to } private val name = filterChecker(useCache = true) { device, filter -> - val regexMatch = device.name?.contains(filter.name.toRegex()) ?: false + val regexMatch = device.name?.checkRegexSafe(filter.name) ?: false val noCaseSubstringMatch = device.name?.contains(filter.name, filter.ignoreCase) ?: false regexMatch || noCaseSubstringMatch } private val address = filterChecker(useCache = true) { device, filter -> - device.address.contains(filter.address.toRegex()) + device.address.checkRegexSafe(filter.address) } private val manufacturer = filterChecker(useCache = true) { device, filter -> device.manufacturerInfo?.id?.let { it == filter.manufacturerId } ?: false diff --git a/app/src/main/java/f/cking/software/ui/devicelist/DeviceListViewModel.kt b/app/src/main/java/f/cking/software/ui/devicelist/DeviceListViewModel.kt index dba038d..24bc70c 100644 --- a/app/src/main/java/f/cking/software/ui/devicelist/DeviceListViewModel.kt +++ b/app/src/main/java/f/cking/software/ui/devicelist/DeviceListViewModel.kt @@ -10,6 +10,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import f.cking.software.BuildConfig import f.cking.software.R +import f.cking.software.checkRegexSafe import f.cking.software.data.helpers.IntentHelper import f.cking.software.data.repo.DevicesRepository import f.cking.software.data.repo.SettingsRepository @@ -294,8 +295,8 @@ class DeviceListViewModel( || (device.customName?.contains(searchStr, true) ?: false) || (device.manufacturerInfo?.name?.contains(searchStr, true) ?: false) || device.address.contains(searchStr, true) - || device.address.contains(query.toRegex()) - || (device.name?.contains(query.toRegex()) ?: false) + || device.address.checkRegexSafe(query) + || (device.name?.checkRegexSafe(query) ?: false) } ?: true } diff --git a/app/src/main/java/f/cking/software/utils/ext.kt b/app/src/main/java/f/cking/software/utils/ext.kt index b7f373f..8ccd197 100644 --- a/app/src/main/java/f/cking/software/utils/ext.kt +++ b/app/src/main/java/f/cking/software/utils/ext.kt @@ -9,6 +9,7 @@ import android.view.Display import android.view.WindowManager import android.widget.Toast import androidx.core.content.ContextCompat +import timber.log.Timber import java.security.MessageDigest import java.time.Instant import java.time.LocalDate @@ -16,6 +17,7 @@ import java.time.LocalDateTime import java.time.LocalTime import java.time.ZoneId import java.time.format.DateTimeFormatter +import java.util.regex.PatternSyntaxException fun Long.getTimePeriodStr(context: Context): String { @@ -125,4 +127,15 @@ fun List.splitToBatches(batchSize: Int): List> { fun Context.isDarkModeOn(): Boolean { val nightModeFlags = resources.configuration.uiMode and android.content.res.Configuration.UI_MODE_NIGHT_MASK return nightModeFlags == android.content.res.Configuration.UI_MODE_NIGHT_YES +} + +fun String.checkRegexSafe(pattern: String): Boolean { + return try { + this.contains(pattern.toRegex()) + } catch (e: PatternSyntaxException) { + false + } catch (e: Throwable) { + Timber.e("Unexpected regex failure", e) + false + } } \ No newline at end of file