Sanitize attachment filenames

This commit is contained in:
M66B 2019-02-19 14:46:20 +00:00
parent 458b1bf6ed
commit 0764e43964
2 changed files with 6 additions and 2 deletions

View File

@ -188,7 +188,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
lbm.sendBroadcast(
new Intent(ActivityView.ACTION_STORE_ATTACHMENT)
.putExtra("id", attachment.id)
.putExtra("name", attachment.name)
.putExtra("name", Helper.sanitizeFilename(attachment.name))
.putExtra("type", attachment.type));
}
@ -205,7 +205,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
intent.setDataAndType(uri, attachment.type);
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
if (!TextUtils.isEmpty(attachment.name))
intent.putExtra(Intent.EXTRA_TITLE, attachment.name);
intent.putExtra(Intent.EXTRA_TITLE, Helper.sanitizeFilename(attachment.name));
Log.i("Sharing " + file + " type=" + attachment.type);
Log.i("Intent=" + intent);

View File

@ -1001,4 +1001,8 @@ public class Helper {
}
return sb.toString();
}
static String sanitizeFilename(String name) {
return (name == null ? null : name.replaceAll("[^a-zA-Z0-9\\.\\-]", "_"));
}
}