Hi!
I am encoding file names using the url-encode function in Hunchentoot. However, it encodes chars such as space and / as well, which makes at least my browser (Firefox) or web server not understand that they are indeed links to files I have shared.
So I have this workaround:
(defun replace-all (string part replacement &key (test #'char=)) "Returns a new string in which all the occurences of the part is replaced with replacement." (with-output-to-string (out) (loop with part-length = (length part) for old-pos = 0 then (+ pos part-length) for pos = (search part string :start2 old-pos :test test) do (write-string string out :start old-pos :end (or pos (length string))) when pos do (write-string replacement out) while pos)))
(defun replace-some-encoded (file-name) ;; Some chars should not be encoded, apparently... (replace-all (replace-all file-name "+" "%20") "%2F" "/"))
(defun url-encode-file-name (file-name) (replace-some-encoded (hunchentoot:url-encode file-name :utf-8)))
The above gives URLs like these:
http://myserver/Tommy%20K%C3%B6rberg%2FTommy%20K%C3%B6rberg%20-%20Stad%20i%2...
And without the workaround I get this:
http://klibb.com/muuartist/Tommy+K%C3%B6rberg%2FTommy+K%C3%B6rberg+-+Anthem....
I searched the doc for "file name" to see if there was some special method suited for encoding file names with path information but could not find one.
Do I need the above workaround?
Thanks!
/Mathias