From beffe1119048f1f26d2ce187e0b681afd8946b14 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 19 Feb 2021 11:54:55 +0100 Subject: [PATCH] RegExp lints fix --- .../maintenance/formats/EncryptedPrefsFormat.kt | 16 ++++++++-------- .../service/RileyLinkMedtronicService.java | 2 +- .../service/RileyLinkOmnipodService.java | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormat.kt b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormat.kt index 3019354d33..2cc83d410c 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormat.kt +++ b/core/src/main/java/info/nightscout/androidaps/plugins/general/maintenance/formats/EncryptedPrefsFormat.kt @@ -24,11 +24,11 @@ class EncryptedPrefsFormat @Inject constructor( companion object { - val FORMAT_KEY_ENC = "aaps_encrypted" - val FORMAT_KEY_NOENC = "aaps_structured" + const val FORMAT_KEY_ENC = "aaps_encrypted" + const val FORMAT_KEY_NOENC = "aaps_structured" - private val KEY_CONSCIENCE = "if you remove/change this, please make sure you know the consequences!" - private val FORMAT_TEST_REGEX = Regex("(\\\"format\\\"\\s*\\:\\s*\\\"aaps_[^\"]*\\\")") + private const val KEY_CONSCIENCE = "if you remove/change this, please make sure you know the consequences!" + private val FORMAT_TEST_REGEX = Regex("(\"format\"\\s*:\\s*\"aaps_[^\"]*\")") } override fun isPreferencesFile(file: File, preloadedContents: String?): Boolean { @@ -94,7 +94,7 @@ class EncryptedPrefsFormat @Inject constructor( var fileContents = container.toString(2) val fileHash = cryptoUtil.hmac256(fileContents, KEY_CONSCIENCE) - fileContents = fileContents.replace(Regex("(\\\"file_hash\\\"\\s*\\:\\s*\\\")(--to-be-calculated--)(\\\")"), "$1" + fileHash + "$3") + fileContents = fileContents.replace(Regex("(\"file_hash\"\\s*:\\s*\")(--to-be-calculated--)(\")"), "$1$fileHash$3") storage.putFileContents(file, fileContents) @@ -112,7 +112,7 @@ class EncryptedPrefsFormat @Inject constructor( try { val jsonBody = storage.getFileContents(file) - val fileContents = jsonBody.replace(Regex("(?is)(\\\"file_hash\\\"\\s*\\:\\s*\\\")([^\"]*)(\\\")"), "$1--to-be-calculated--$3") + val fileContents = jsonBody.replace(Regex("(?is)(\"file_hash\"\\s*:\\s*\")([^\"]*)(\")"), "$1--to-be-calculated--$3") val calculatedFileHash = cryptoUtil.hmac256(fileContents, KEY_CONSCIENCE) val container = JSONObject(jsonBody) val metadata: MutableMap = loadMetadata(container) @@ -192,7 +192,7 @@ class EncryptedPrefsFormat @Inject constructor( if (decryptedOk && contentJsonObj != null) { for (key in contentJsonObj.keys()) { - entries.put(key, contentJsonObj[key].toString()) + entries[key] = contentJsonObj[key].toString() } } @@ -213,7 +213,7 @@ class EncryptedPrefsFormat @Inject constructor( } catch (e: IOException) { throw PrefIOError(file.absolutePath) } catch (e: JSONException) { - throw PrefFormatError("Mallformed preferences JSON file: " + e) + throw PrefFormatError("Mallformed preferences JSON file: $e") } } diff --git a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java index 17f2932200..5447240b04 100644 --- a/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java +++ b/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/service/RileyLinkMedtronicService.java @@ -184,7 +184,7 @@ public class RileyLinkMedtronicService extends RileyLinkService { public boolean verifyConfiguration(boolean forceRileyLinkAddressRenewal) { try { String regexSN = "[0-9]{6}"; - String regexMac = "([\\da-fA-F]{1,2}(?:\\:|$)){6}"; + String regexMac = "([\\da-fA-F]{1,2}(?::|$)){6}"; medtronicPumpStatus.errorDescription = "-"; diff --git a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/rileylink/service/RileyLinkOmnipodService.java b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/rileylink/service/RileyLinkOmnipodService.java index 89524f0129..9a8485f689 100644 --- a/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/rileylink/service/RileyLinkOmnipodService.java +++ b/omnipod-eros/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/eros/rileylink/service/RileyLinkOmnipodService.java @@ -32,7 +32,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.eros.util.AapsOmnipodUtil */ public class RileyLinkOmnipodService extends RileyLinkService { - private static final String REGEX_MAC = "([\\da-fA-F]{1,2}(?:\\:|$)){6}"; + private static final String REGEX_MAC = "([\\da-fA-F]{1,2}(?::|$)){6}"; @Inject OmnipodErosPumpPlugin omnipodErosPumpPlugin; @Inject AapsOmnipodUtil aapsOmnipodUtil;