Fix #242 Null AutoType

This commit is contained in:
J-Jamet
2019-09-11 18:03:03 +02:00
parent c5e2ca9907
commit 94244cd15b
6 changed files with 35 additions and 29 deletions

View File

@@ -292,11 +292,11 @@ class GroupVersioned : NodeVersioned, PwGroupInterface<GroupVersioned, EntryVers
pwGroupV4?.nodeId = id
}
fun setEnableAutoType(enableAutoType: Boolean) {
fun setEnableAutoType(enableAutoType: Boolean?) {
pwGroupV4?.enableAutoType = enableAutoType
}
fun setEnableSearching(enableSearching: Boolean) {
fun setEnableSearching(enableSearching: Boolean?) {
pwGroupV4?.enableSearching = enableSearching
}

View File

@@ -122,6 +122,7 @@ object PwDatabaseV4XML {
const val ValFalse = "False"
const val ValTrue = "True"
const val ValNull = "Null"
const val ElemCustomData = "CustomData"
const val ElemStringDictExItem = "Item"

View File

@@ -45,8 +45,8 @@ class PwGroupV4 : PwGroup<UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
var notes = ""
var isExpanded = true
var defaultAutoTypeSequence = ""
var enableAutoType: Boolean = true
var enableSearching: Boolean = true
var enableAutoType: Boolean? = null
var enableSearching: Boolean? = null
var lastTopVisibleEntry: UUID = PwDatabase.UUID_ZERO
override val type: Type
@@ -70,8 +70,10 @@ class PwGroupV4 : PwGroup<UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
notes = parcel.readString() ?: notes
isExpanded = parcel.readByte().toInt() != 0
defaultAutoTypeSequence = parcel.readString() ?: defaultAutoTypeSequence
enableAutoType = parcel.readByte().toInt() != 0
enableSearching = parcel.readByte().toInt() != 0
val isAutoTypeEnabled = parcel.readInt()
enableAutoType = if (isAutoTypeEnabled == -1) null else isAutoTypeEnabled == 1
val isSearchingEnabled = parcel.readInt()
enableSearching = if (isSearchingEnabled == -1) null else isSearchingEnabled == 1
lastTopVisibleEntry = parcel.readSerializable() as UUID
}
@@ -92,8 +94,8 @@ class PwGroupV4 : PwGroup<UUID, PwGroupV4, PwEntryV4>, PwNodeV4Interface {
dest.writeString(notes)
dest.writeByte((if (isExpanded) 1 else 0).toByte())
dest.writeString(defaultAutoTypeSequence)
dest.writeByte((if (enableAutoType) 1 else 0).toByte())
dest.writeByte((if (enableSearching) 1 else 0).toByte())
dest.writeInt(if (enableAutoType == null) -1 else if (enableAutoType!!) 1 else 0)
dest.writeInt(if (enableSearching == null) -1 else if (enableSearching!!) 1 else 0)
dest.writeSerializable(lastTopVisibleEntry)
}

View File

@@ -39,6 +39,9 @@ abstract class Importer<PwDb : PwDatabase<*, *>> {
* @throws InvalidDBException on database error.
*/
@Throws(IOException::class, InvalidDBException::class)
abstract fun openDatabase(databaseInputStream: InputStream, password: String?, keyInputStream: InputStream?, progressTaskUpdater: ProgressTaskUpdater?): PwDb
abstract fun openDatabase(databaseInputStream: InputStream,
password: String?,
keyInputStream: InputStream?,
progressTaskUpdater: ProgressTaskUpdater?): PwDb
}

View File

@@ -490,9 +490,9 @@ class ImporterV4(private val streamDir: File) : Importer<PwDatabaseV4>() {
} else if (name.equals(PwDatabaseV4XML.ElemGroupDefaultAutoTypeSeq, ignoreCase = true)) {
ctxGroup?.defaultAutoTypeSequence = readString(xpp)
} else if (name.equals(PwDatabaseV4XML.ElemEnableAutoType, ignoreCase = true)) {
ctxGroup?.enableAutoType = stringToBoolean(readString(xpp))
ctxGroup?.enableAutoType = readOptionalBool(xpp)
} else if (name.equals(PwDatabaseV4XML.ElemEnableSearching, ignoreCase = true)) {
ctxGroup?.enableSearching = stringToBoolean(readString(xpp))
ctxGroup?.enableSearching = readOptionalBool(xpp)
} else if (name.equals(PwDatabaseV4XML.ElemLastTopVisibleEntry, ignoreCase = true)) {
ctxGroup?.lastTopVisibleEntry = readUuid(xpp)
} else if (name.equals(PwDatabaseV4XML.ElemCustomData, ignoreCase = true)) {
@@ -847,7 +847,23 @@ class ImporterV4(private val streamDir: File) : Importer<PwDatabaseV4>() {
private fun readBool(xpp: XmlPullParser, bDefault: Boolean): Boolean {
val str = readString(xpp)
return str.equals("true", ignoreCase = true) || !str.equals("false", ignoreCase = true) && bDefault
return when {
str.equals(PwDatabaseV4XML.ValTrue, ignoreCase = true) -> true
str.equals(PwDatabaseV4XML.ValFalse, ignoreCase = true) -> false
else -> bDefault
}
}
@Throws(IOException::class, XmlPullParserException::class)
private fun readOptionalBool(xpp: XmlPullParser, bDefault: Boolean? = null): Boolean? {
val str = readString(xpp)
return when {
str.equals(PwDatabaseV4XML.ValTrue, ignoreCase = true) -> true
str.equals(PwDatabaseV4XML.ValFalse, ignoreCase = true) -> false
str.equals(PwDatabaseV4XML.ValNull, ignoreCase = true) -> null
else -> bDefault
}
}
@Throws(IOException::class, XmlPullParserException::class)
@@ -1032,22 +1048,6 @@ class ImporterV4(private val streamDir: File) : Importer<PwDatabaseV4>() {
return ctxNew
}
private fun stringToBoolean(str: String?): Boolean {
if (str == null || str.isEmpty()) {
return false
}
val trimmed = str.trim { it <= ' ' }
if (trimmed.equals("true", ignoreCase = true)) {
return true
} else if (trimmed.equals("false", ignoreCase = true)) {
return false
}
return false
}
companion object {
private const val DEFAULT_HISTORY_DAYS: Long = 365

View File

@@ -496,7 +496,7 @@ class PwDbV4Output(private val mDatabaseV4: PwDatabaseV4, outputStream: OutputSt
@Throws(IllegalArgumentException::class, IllegalStateException::class, IOException::class)
private fun writeObject(name: String, value: Boolean?) {
val text: String = when {
value == null -> "null"
value == null -> PwDatabaseV4XML.ValNull
value -> PwDatabaseV4XML.ValTrue
else -> PwDatabaseV4XML.ValFalse
}