xwikisas / macro-pdfviewer

0 stars 4 forks source link

PDF files with spaces in their names are not properly viewed anymore #35

Closed mflorea closed 2 years ago

mflorea commented 2 years ago

This is a regression in v2.3. Before 2.3 the list of files was obtained by splitting the value of the file parameter by comma. See https://github.com/xwikisas/macro-pdfviewer/blob/macro-pdfviewer-2.2.1/wiki/src/main/resources/XWiki/PDFViewerMacro.xml#L271

#set ($files = $fileParam.split(','))

The PDF Viewer Macro was moved to Java in v2.3 and the PDFViewerMacroParameters is using List<String> as type for the file macro parameter.

#set ($files = $params.files)

The string value provided by the user when calling the macro is converted automatically to a list using the ListConverter which splits the string, by default, using comma or space. This is an unexpected change in behavior. Note that the (default) ListConverter does other "cleanup" (removes { from the start and } from the end, which might lead to other surprises, although having such file names is rare) so I'm not sure it's a good idea to use it. We need to either write / use a custom converter or (probably safer) to make the file parameter a string and to do the split ourselves as before.

BTW, the way we handle the file parameter in PDFViewerMacroParameters is a bit hackish, with setFile (singural) and getFiles (plural). I'm sorry I didn't catch this on review.

ane-gabriela commented 2 years ago

Example of what a PDF with spaces in the name looked like with PDF Viewer in v2.3

PDF with spaces in name