check for valid JSON on import
This commit is contained in:
parent
b511cc147f
commit
b31e328022
1 changed files with 12 additions and 2 deletions
|
@ -35,6 +35,13 @@ class EncryptedPrefsFormat @Inject constructor(
|
||||||
return if (file.absolutePath.endsWith(".json")) {
|
return if (file.absolutePath.endsWith(".json")) {
|
||||||
val contents = preloadedContents ?: storage.getFileContents(file)
|
val contents = preloadedContents ?: storage.getFileContents(file)
|
||||||
FORMAT_TEST_REGEX.containsMatchIn(contents)
|
FORMAT_TEST_REGEX.containsMatchIn(contents)
|
||||||
|
try {
|
||||||
|
// test valid JSON object
|
||||||
|
JSONObject(contents)
|
||||||
|
true
|
||||||
|
} catch (e: Exception) {
|
||||||
|
false
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
@ -219,8 +226,11 @@ class EncryptedPrefsFormat @Inject constructor(
|
||||||
|
|
||||||
override fun loadMetadata(contents: String?): PrefMetadataMap {
|
override fun loadMetadata(contents: String?): PrefMetadataMap {
|
||||||
contents?.let {
|
contents?.let {
|
||||||
val container = JSONObject(contents)
|
return try {
|
||||||
return loadMetadata(container)
|
loadMetadata(JSONObject(contents))
|
||||||
|
} catch (e: Exception) {
|
||||||
|
mutableMapOf()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return mutableMapOf()
|
return mutableMapOf()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue