Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/src/main/java/fr/free/nrw/commons/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static int licenseNameFor(String license) {
}

/**
* 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
Expand All @@ -128,6 +128,15 @@ public static String fixExtension(String title, String extension) {
.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;
}

Expand Down
10 changes: 10 additions & 0 deletions app/src/test/kotlin/fr/free/nrw/commons/UtilsFixExtensionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}