Skip to content

Conversation

neslihanturan
Copy link
Collaborator

Title (required)

Fixes #228 Override happens

Description (required)

Fixes #228 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. Otherwise overrides are possible.

Tests performed (required)

BetaDebug, API level 19 (this was the only emulator that I could reproduce the issue)

Fixedthe problem for me.

…ion. 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.
@whym
Copy link
Collaborator

whym commented Aug 19, 2018

Perhaps we should also check 'title' is without any extension? Some of the tests fail because results like "SampleFile.jpg.jpg" are returned in UtilsFixExtensionTest (and I believe they should not).

And I also suggest adding a new test like this:

@Test
    fun noInformationShouldResultsInJpg() {
        // when null, fall back to jpg (but this solution might not be complete - see PR #1838)
        assertEquals("SampleFile.jpg", fixExtension("SampleFile", null))
    }

We might have to read the content of the file and guess mimetype/extension. (I believe there is a library for doing that.) That could be a separate issue to be worked on, as it might take time to implement.

@neslihanturan
Copy link
Collaborator Author

Thanks for catching @whym . I never thought title with extension possibility. And I will add the test you offered:)

@codecov-io
Copy link

codecov-io commented Aug 20, 2018

Codecov Report

Merging #1838 into 2.8-release will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@              Coverage Diff               @@
##           2.8-release   #1838      +/-   ##
==============================================
+ Coverage         3.64%   3.67%   +0.03%     
==============================================
  Files              188     188              
  Lines             9544    9547       +3     
  Branches           843     844       +1     
==============================================
+ Hits               348     351       +3     
  Misses            9172    9172              
  Partials            24      24
Impacted Files Coverage Δ
app/src/main/java/fr/free/nrw/commons/Utils.java 27.39% <100%> (+3.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 11c3772...15ca64c. Read the comment docs.

@misaochan misaochan changed the title This solution is an hotfix for overrite issue came back on 2.8.0 Hotfix for overwrite issue in 2.8.0 Aug 20, 2018
@misaochan
Copy link
Member

Tests:

Uploading a .jpg file via Share or in-app button both work, and does not overwrite
Uploading a .png file via Share fails
Uploading a .png file via in-app button works, and does not overwrite

Merging this for the hotfix anyway, thanks!

@misaochan misaochan merged commit 4c476e7 into commons-app:2.8-release Aug 20, 2018
@maskaravivek
Copy link
Member

maskaravivek commented Aug 20, 2018

Uploading a .png file via Share fails

@misaochan Can you share logs for this scenario.

Edit: Ignore, I just saw your comment on the issue thread. :)

maskaravivek added a commit that referenced this pull request Sep 7, 2018
* Add Traceur for getting meaningful RxJava stack traces (#1832)

* 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

* Versioning and changelog for v2.8.2 (#1842)

* Versioning for v2.8.2

* Changelog for v2.8.2

* Add logs in wiki data edit and session refresh flow (#1874)

* Fix logout (#1875)

* [WIP] Refactor feedback and quiz to reduce possibility of NPE (#1881)

* Refactor feedback and quiz to reduce possibility of NPE

* Handle throwables in quiz checker

* Minor refactoring

* Set Traceur to only work in DEBUG mode (#1884)

* Bug fix for uploaded images count in achievements activity (#1885)

* Versioning and changelog for v2.8.3 (#1886)

* Update changelog.md

* Versioning for v2.8.3
neslihanturan pushed a commit that referenced this pull request Dec 20, 2018
* Add Traceur for getting meaningful RxJava stack traces (#1832)

* 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

* Versioning and changelog for v2.8.2 (#1842)

* Versioning for v2.8.2

* Changelog for v2.8.2

* Delete unused MaterialShowcase class

* Add Javadocs and fix lint errors for DirectUpload.java

* Fix whitespace and add docs

* Replace fragment.getActivity() with the parentActivity var

* Rename unnecessarily-overloaded method getFromWikidataQuery(), add Javadocs

* Javadocs and whitespaces for NearbyPlaces.java

* Use local vars where possible instead of class fields. Non-constants should not be in all caps

* Missed one unnecessary class field

* Remove unnecessary whitespaces that don't improve readability

* Add class summary

* Optimize imports

* Fix access modifiers in Place.java

* Clearer Javadocs

* Add Javadocs to Place.java

* Remove residual conflict

* Fix lint issues in Sitelinks

* Javadocs for Sitelinks.java

* DirectUpload: Replace nested conditionals with guard clauses
maskaravivek pushed a commit that referenced this pull request Nov 27, 2019
* Add Traceur for getting meaningful RxJava stack traces (#1832)

* 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

* Versioning and changelog for v2.8.2 (#1842)

* Versioning for v2.8.2

* Changelog for v2.8.2

* Fix data template for other source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants