MM-33495 Sanitize filename in Android ShareExtension (#5210)
* MM-33495 Sanitize filename in Android ShareExtension * Apply sanitization after getting uri last path segment Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
parent
5f6552a649
commit
86a096d1ce
1 changed files with 17 additions and 3 deletions
|
|
@ -96,20 +96,25 @@ public class RealPathUtil {
|
|||
File tmpFile;
|
||||
String fileName = null;
|
||||
|
||||
if (uri == null || uri.isRelative()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Try and get the filename from the Uri
|
||||
try {
|
||||
Cursor returnCursor =
|
||||
context.getContentResolver().query(uri, null, null, null, null);
|
||||
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||
returnCursor.moveToFirst();
|
||||
fileName = returnCursor.getString(nameIndex);
|
||||
fileName = sanitizeFilename(returnCursor.getString(nameIndex));
|
||||
|
||||
} catch (Exception e) {
|
||||
// just continue to get the filename with the last segment of the path
|
||||
}
|
||||
|
||||
try {
|
||||
if (fileName == null) {
|
||||
fileName = uri.getLastPathSegment().toString().trim();
|
||||
if (TextUtils.isEmpty(fileName)) {
|
||||
fileName = sanitizeFilename(uri.getLastPathSegment().toString().trim());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -230,4 +235,13 @@ public class RealPathUtil {
|
|||
|
||||
fileOrDirectory.delete();
|
||||
}
|
||||
|
||||
private static String sanitizeFilename(String filename) {
|
||||
if (filename == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
File f = new File(filename);
|
||||
return f.getName();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue