From e2652ce02f6d743940c846f6faf263054e018a4b Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 3 Apr 2018 21:00:15 +0200 Subject: [PATCH] mod_http_upload: Accept characters of any script Accept all alphanumeric characters of any script in user and file names rather than replacing non-ASCII characters with underscores. However, non-alphanumeric characters are still replaced, except for "." and "-". Closes #2346. --- src/mod_http_upload.erl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/mod_http_upload.erl b/src/mod_http_upload.erl index 0a087124a..4e522e9b1 100644 --- a/src/mod_http_upload.erl +++ b/src/mod_http_upload.erl @@ -671,21 +671,31 @@ mk_slot(Slot, #state{put_url = PutPrefix, get_url = GetPrefix}, XMLNS) -> GetURL = str:join([GetPrefix | Slot], <<$/>>), mk_slot(PutURL, GetURL, XMLNS); mk_slot(PutURL, GetURL, ?NS_HTTP_UPLOAD_0) -> - #upload_slot_0{get = GetURL, put = PutURL, xmlns = ?NS_HTTP_UPLOAD_0}; + #upload_slot_0{get = misc:url_encode(GetURL), + put = misc:url_encode(PutURL), + xmlns = ?NS_HTTP_UPLOAD_0}; mk_slot(PutURL, GetURL, XMLNS) -> - #upload_slot{get = GetURL, put = PutURL, xmlns = XMLNS}. + #upload_slot{get = misc:url_encode(GetURL), + put = misc:url_encode(PutURL), + xmlns = XMLNS}. -spec make_user_string(jid(), sha1 | node) -> binary(). make_user_string(#jid{luser = U, lserver = S}, sha1) -> str:sha(<>); make_user_string(#jid{luser = U}, node) -> - re:replace(U, <<"[^a-zA-Z0-9_.-]">>, <<$_>>, [global, {return, binary}]). + replace_special_chars(U). -spec make_file_string(binary()) -> binary(). make_file_string(File) -> - re:replace(File, <<"[^a-zA-Z0-9_.-]">>, <<$_>>, [global, {return, binary}]). + replace_special_chars(File). + +-spec replace_special_chars(binary()) -> binary(). + +replace_special_chars(S) -> + re:replace(S, <<"[^\\p{Xan}_.-]">>, <<$_>>, + [unicode, global, {return, binary}]). -spec yield_content_type(binary()) -> binary().