mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Hotfix for overwrite issue in 2.8.0 (#1838)
* This solution is an hotfix for overrite issue came back on 2.8.0 version. What I did is checking the extension, and if it is null, adding .jpg suffix. Because commons files always have suffixes, and we should compare file names after adding suffixes. Othervise overrides are possible. * Check if file title includes an extension already, by checking if is there any dot in it. * Fix logic error * Add uncovered tests * Remove unecessary line breaks * Make Javadocs more explicit
This commit is contained in:
parent
11c3772dd0
commit
4c476e7a06
2 changed files with 20 additions and 1 deletions
|
|
@ -111,7 +111,7 @@ public class Utils {
|
|||
}
|
||||
|
||||
/**
|
||||
* Fixing incorrect extension
|
||||
* Adds extension to filename. Converts to .jpg if system provides .jpeg, adds .jpg if no extension detected
|
||||
* @param title File name
|
||||
* @param extension Correct extension
|
||||
* @return File with correct extension
|
||||
|
|
@ -128,6 +128,15 @@ public class Utils {
|
|||
.endsWith("." + extension.toLowerCase(Locale.ENGLISH))) {
|
||||
title += "." + extension;
|
||||
}
|
||||
|
||||
// If extension is still null, make it jpg. (Hotfix for https://github.com/commons-app/apps-android-commons/issues/228)
|
||||
// If title has an extension in it, if won't be true
|
||||
// FIXME: .png uploads fail when uploaded via Share
|
||||
if (extension == null && title.lastIndexOf(".")<=0) {
|
||||
extension = "jpg";
|
||||
title += "." + extension;
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,4 +65,14 @@ class UtilsFixExtensionTest {
|
|||
fun inWordJpegToJpgResultsInJpg() {
|
||||
assertEquals("X.jpeg.SAMPLE.jpg", fixExtension("X.jpeg.SAMPLE", "jpg"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noExtensionShouldResultInJpg() {
|
||||
assertEquals("Sample.jpg", fixExtension("Sample", null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun extensionAlreadyInTitleShouldRemain() {
|
||||
assertEquals("Sample.jpg", fixExtension("Sample.jpg", null))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue