Skip to content

URL Decode filename for resources uploaded by url#8628

Merged
josegar74 merged 3 commits intogeonetwork:mainfrom
tylerjmchugh:main.decode-urls-for-putResourceFromUrl
Feb 6, 2025
Merged

URL Decode filename for resources uploaded by url#8628
josegar74 merged 3 commits intogeonetwork:mainfrom
tylerjmchugh:main.decode-urls-for-putResourceFromUrl

Conversation

@tylerjmchugh
Copy link
Contributor

Currently the putResourceFromUrl API gets the file name from the URL itself but does not consider URL encoded characters. This means if a URL like http://domain.com/dictionnaire%20de%20donn%C3%A9es.pdf is provided the uploaded file's name will be dictionnaire%20de%20donn%C3%A9es.pdf.

This PR aims to fix this issue by URL decoding the filename. With this fix the filename would be dictionnaire de données.pdf as intended.

Checklist

  • I have read the contribution guidelines
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests
  • User documentation provided for new features or enhancements in manual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

@ianwallen ianwallen added the bug label Jan 29, 2025
@ianwallen ianwallen added this to the 4.4.7 milestone Jan 29, 2025
@josegar74 josegar74 self-requested a review January 30, 2025 15:51
Copy link
Member

@josegar74 josegar74 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works fine.

Please @tylerjmchugh can you check to add a test in https://github.com/geonetwork/core-geonetwork/blob/main/core/src/test/java/org/fao/geonet/api/records/attachments/FilesystemStoreTest.java

    @Test
    public void testGetFilenameFromUrl() throws Exception {
        FilesystemStore filesystemStore = new FilesystemStore();

        String fileName = filesystemStore.getFilenameFromUrl(new URL("http://mydomain.com/filename.txt"));
        assertEquals("filename.txt", fileName);

        fileName = filesystemStore.getFilenameFromUrl(new URL("http://mydomain.com/filename%20with%20spaces.txt"));
        assertEquals("filename with spaces.txt", fileName);
    }

@ianwallen ianwallen requested a review from josegar74 February 5, 2025 18:05
@josegar74 josegar74 merged commit 03c2aae into geonetwork:main Feb 6, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants