fix #173, check invalid characters at filenames

This commit is contained in:
tibbi 2018-02-22 23:42:04 +01:00
parent 324f37ad38
commit 1665de156a
3 changed files with 14 additions and 11 deletions

View File

@ -45,7 +45,7 @@ ext {
}
dependencies {
implementation 'com.simplemobiletools:commons:3.12.20'
implementation 'com.simplemobiletools:commons:3.12.21'
implementation 'com.facebook.stetho:stetho:1.5.0'
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"

View File

@ -369,13 +369,17 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
mNotes.forEachIndexed { index, note ->
val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension"
val file = File(parent, filename)
exportNoteValueToFile(file.absolutePath, note.value, false) {
if (!it) {
failCount++
}
if (!filename.isAValidFilename()) {
toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename)))
} else {
exportNoteValueToFile(file.absolutePath, note.value, false) {
if (!it) {
failCount++
}
if (index == mNotes.size - 1) {
toast(if (failCount == 0) R.string.exporting_successful else R.string.exporting_some_entries_failed)
if (index == mNotes.size - 1) {
toast(if (failCount == 0) R.string.exporting_successful else R.string.exporting_some_entries_failed)
}
}
}
}

View File

@ -44,15 +44,14 @@ class ExportFileDialog(val activity: SimpleActivity, val note: Note, val callbac
}
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
val newFile = File(realPath, fullFilename)
if (!newFile.name.isAValidFilename()) {
activity.toast(R.string.filename_invalid_characters)
if (!fullFilename.isAValidFilename()) {
activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename)))
return@setOnClickListener
}
activity.config.lastUsedExtension = extension
activity.config.lastUsedSavePath = realPath
callback(newFile.absolutePath)
callback("$realPath/$fullFilename")
dismiss()
}
}