[BUGFIX] Make rewriteFilenameForUri handle non-ASCII names correctly
When the filename consists completely of non-ASCII characters,
the ``rewriteFilenameForUri`` would substitute it with empty filename
like ".jpg", resulting in a broken resource link.
This change makes ``rewriteFilenameForUri`` accept unicode character.
In addition it checks if the filename is empty after the rewrite and
names it "unnamed.<fileExtension>" if needed.
Releases: master, 2.1, 2.2, 2.3