URL Decode filename for resources uploaded by url#8628
Merged
josegar74 merged 3 commits intogeonetwork:mainfrom Feb 6, 2025
Merged
URL Decode filename for resources uploaded by url#8628josegar74 merged 3 commits intogeonetwork:mainfrom
josegar74 merged 3 commits intogeonetwork:mainfrom
Conversation
josegar74
reviewed
Jan 31, 2025
Member
josegar74
left a comment
There was a problem hiding this comment.
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);
}
josegar74
approved these changes
Feb 6, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.pdfis provided the uploaded file's name will bedictionnaire%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.pdfas intended.Checklist
mainbranch, backports managed with labelREADME.mdfilespom.xmldependency management. Update build documentation with intended library use and library tutorials or documentation