Skip to content

Commit

Permalink
better input validation for bookmarks dialog. fixes #4337, #4336, #4335
Browse files Browse the repository at this point in the history
… & #4334
  • Loading branch information
VishnuSanal committed Jan 12, 2025
1 parent 5cb924a commit 4bdd551
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class BookmarksPrefsFragment : BasePrefsFragment() {
path: String,
): Pair<Boolean, Int> {
return when {
name.isEmpty() -> Pair(false, R.string.invalid_name)
name.isEmpty() || path.isEmpty() -> Pair(false, R.string.invalid_name)
dataUtils.containsBooks(arrayOf(name, path)) != -1 -> Pair(false, R.string.bookmark_exists)
!FileUtils.isPathAccessible(path, activity.prefs) -> Pair(false, R.string.ftp_path_change_error_invalid)
else -> Pair(true, 0)
Expand Down Expand Up @@ -190,6 +190,17 @@ class BookmarksPrefsFragment : BasePrefsFragment() {
.setOnClickListener {
val oldName = p.title.toString()
val oldPath = p.summary.toString()

val result = isValidBookmark(editText1.text.toString(), editText2.text.toString())
if (!result.first) {
Toast.makeText(
requireContext(),
requireContext().getString(result.second),
Toast.LENGTH_SHORT,
).show()
return@setOnClickListener

Check warning on line 201 in app/src/main/java/com/amaze/filemanager/ui/fragments/preferencefragments/BookmarksPrefsFragment.kt

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

app/src/main/java/com/amaze/filemanager/ui/fragments/preferencefragments/BookmarksPrefsFragment.kt#L201

Expression with labels increase complexity and affect maintainability.
}

dataUtils.removeBook(position[p]!!)
position.remove(p)
bookmarksList?.removePreference(p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ int contains(String[] a, ArrayList<String[]> b) {
if (b == null) return -1;
int i = 0;
for (String[] x : b) {
if (x[0].equals(a[0]) && x[1].equals(a[1])) return i;
if (x[0].equals(a[0]) || x[1].equals(a[1])) return i;
i++;
}
return -1;
Expand Down

0 comments on commit 4bdd551

Please sign in to comment.