Skip to content

Commit 1665de1

Browse files
committed
fix #173, check invalid characters at filenames
1 parent 324f37a commit 1665de1

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ext {
4545
}
4646

4747
dependencies {
48-
implementation 'com.simplemobiletools:commons:3.12.20'
48+
implementation 'com.simplemobiletools:commons:3.12.21'
4949
implementation 'com.facebook.stetho:stetho:1.5.0'
5050

5151
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"

app/src/main/kotlin/com/simplemobiletools/notes/activities/MainActivity.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,17 @@ class MainActivity : SimpleActivity(), ViewPager.OnPageChangeListener {
369369
mNotes.forEachIndexed { index, note ->
370370
val filename = if (extension.isEmpty()) note.title else "${note.title}.$extension"
371371
val file = File(parent, filename)
372-
exportNoteValueToFile(file.absolutePath, note.value, false) {
373-
if (!it) {
374-
failCount++
375-
}
376-
377-
if (index == mNotes.size - 1) {
378-
toast(if (failCount == 0) R.string.exporting_successful else R.string.exporting_some_entries_failed)
372+
if (!filename.isAValidFilename()) {
373+
toast(String.format(getString(R.string.filename_invalid_characters_placeholder, filename)))
374+
} else {
375+
exportNoteValueToFile(file.absolutePath, note.value, false) {
376+
if (!it) {
377+
failCount++
378+
}
379+
380+
if (index == mNotes.size - 1) {
381+
toast(if (failCount == 0) R.string.exporting_successful else R.string.exporting_some_entries_failed)
382+
}
379383
}
380384
}
381385
}

app/src/main/kotlin/com/simplemobiletools/notes/dialogs/ExportFileDialog.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ class ExportFileDialog(val activity: SimpleActivity, val note: Note, val callbac
4444
}
4545

4646
val fullFilename = if (extension.isEmpty()) filename else "$filename.$extension"
47-
val newFile = File(realPath, fullFilename)
48-
if (!newFile.name.isAValidFilename()) {
49-
activity.toast(R.string.filename_invalid_characters)
47+
if (!fullFilename.isAValidFilename()) {
48+
activity.toast(String.format(activity.getString(R.string.filename_invalid_characters_placeholder, fullFilename)))
5049
return@setOnClickListener
5150
}
5251

5352
activity.config.lastUsedExtension = extension
5453
activity.config.lastUsedSavePath = realPath
55-
callback(newFile.absolutePath)
54+
callback("$realPath/$fullFilename")
5655
dismiss()
5756
}
5857
}

0 commit comments

Comments
 (0)