ruven / iipsrv

iipsrv is an advanced high-performance feature-rich image server for web-based streamed viewing and zooming of ultra high-resolution images.
https://iipimage.sourceforge.io
GNU General Public License v3.0
292 stars 115 forks source link

File names with comma no longer work #261

Closed andersju closed 1 year ago

andersju commented 1 year ago

https://github.com/ruven/iipsrv/commit/d978bfde03955150bbc9fee37836d3fa52763a7a "[a]dded ability to choose a particular page or slice in an image stack when using IIIF by using a comma delimitter after the file name", but unfortunately this breaks file names that contain ,, because the request URI isn't parsed correctly -- the comma and everything after it is chopped off from the file name in the decoding/filtering step, and is instead interpreted as a request for a certain page or slice.

Given the file /data/foo,bar.jp2:

Previously (6f3a93dbe22dbb68c77a783955f0b832682d2332):

Request URI mapped to iiif=%2Fdata%2Ffoo%2Cbar.jp2/info.json
Full Request is iiif=%2Fdata%2Ffoo%2Cbar.jp2/info.json
[1/1]: Command / Argument is iiif : %2Fdata%2Ffoo%2Cbar.jp2/info.json
IIIF handler reached
IIIF :: URL decoded to /data/foo,bar.jp2/info.json
FIF handler reached
FIF :: URL decoding/filtering: /data/foo,bar.jp2 => /data/foo,bar.jp2
FIF :: Image cache initialization
FIF :: JPEG2000 image detected
...

Since d978bfde03955150bbc9fee37836d3fa52763a7a:

Request URI mapped to iiif=%2Fdata%2Ffoo%2Cbar.jp2/info.json
Full Request is iiif=%2Fdata%2Ffoo%2Cbar.jp2/info.json
[1/1]: Command / Argument is iiif : %2Fdata%2Ffoo%2Cbar.jp2/info.json
IIIF handler reached
IIIF :: URL decoded to /data/foo,bar.jp2/info.json
IIIF :: Requested stack or page index: 0
FIF handler reached
FIF :: URL decoding/filtering: /data/foo => /data/foo
FIF :: Image cache initialization
/data/foo is neither a file nor part of an image sequence
Sending HTTP 404 Not Found
ruven commented 1 year ago

Maybe the separator should be configurable. I notice that Cantaloupe also has multi-page functionality, but uses a semi-colon rather than a comma (https://cantaloupe-project.github.io/manual/5.0/images.html#Identifiers). Would a semi-colon be better? Or perhaps some other symbol? What other kinds of punctuation do you have in your image names?

andersju commented 1 year ago

I think making it configurable (like in Cantaloupe, which we switched from :)) is probably ideal (even just a #define would be good), but for our particular case semi-colon is definitely better than comma (and I suspect semi-colon is less common in file names in general).

(I'm unfortunately not sure what kinds of punctuation we use in file names, but we used the default ; delimiter in Cantaloupe, and if it's configurable we can always figure something out. In our case: we don't need multi-page functionality, so if I can't figure out a "safe" regular character I'd probably set it to some non-printable character to effectively disable it.)

ruven commented 1 year ago

This should now be fixed. I've added a new IIIF_DELIMITER configuration parameter where you can specify exactly the kind of IIIF delimiter you want, which can be a character or even any arbitrary string. This feature is disabled by default and only activated if you set the IIIF_DELIMITER parameter.

andersju commented 1 year ago

Yep, it works fine now. Thank you!