requarks / wiki-v1

Legacy version (1.x) of Wiki.js
https://wiki.js.org
GNU Affero General Public License v3.0
101 stars 75 forks source link

Can not download file whose filename is in chinese #56

Open bit-jmm opened 6 years ago

bit-jmm commented 6 years ago

Actual behavior

Can not download file whose filename is in chinese

Steps to reproduce the behavior

upload a file whose filename is in chinese,then download it,not found occur。

NGPixel commented 6 years ago

Non-latin characters are not supported in search and filenames in 1.x.

Full Chinese support will come in 2.0.

celadevra commented 5 years ago

The same happens to images with CJK chars in file names. I may have a solution by patching server/controllers/uploads.js.

--- uploads.js  2019-03-27 10:14:34.192495616 +0800
+++ uploads-new.js  2019-03-27 10:13:52.451098770 +0800
@@ -12,7 +12,7 @@
 const path = require('path')
 const _ = require('lodash')

-const validPathRe = new RegExp('^([a-z0-9/-' + appdata.regex.cjk + appdata.regex.arabic + ']+\\.[a-z0-9]+)$')
+const validPathRe = new RegExp('^([a-z0-9\-/' + appdata.regex.cjk + appdata.regex.arabic + ']+\\.[a-z0-9]+)$')
 const validPathThumbsRe = new RegExp('^([a-z0-9]+\\.png)$')

 // ==========================================

The original RegExp maybe incorrectly interpreted '-' and the following CJK ranges. After the patch I can download attachments and images with Chinese file names. I am running stable release of Wiki.js 1.0.117 in a docker container based on official debian stretch, with node v10.15.3.

Testing in browser console shows the same results:

>> regexArabic = '\u0600-\u06ff\u0750-\u077f\ufb50-\ufc3f\ufe70-\ufefc'
"؀-ۿݐ-ݿﭐ-ﰿﹰ-ﻼ"
>> var regexCjk = '\u4E00-\u9FBF\u3040-\u309F\u30A0-\u30FFㄱ-ㅎ가-힣ㅏ-ㅣ'
undefined
>> var myValidPathRe = new RegExp('^([a-z0-9/-' + regexCjk + regexArabic + ']+\\.[a-z0-9]+)$')
undefined
>> myValidPathRe.test('uploads/test/abcd-efg.docx')
true
>> myValidPathRe.test('uploads/test/一二三四-efg.docx')
false
>> var myValidPathRe = new RegExp('^([a-z0-9\-/' + regexCjk + regexArabic + ']+\\.[a-z0-9]+)$')
undefined
>> myValidPathRe.test('uploads/test/abcd-efg.docx')
true
>> myValidPathRe.test('uploads/test/一二三四-efg.docx')
true

@NGPixel Could you please look at this and see if the hack is acceptable and whether 2.0 needs similar tweak? I am not familiar with JavaScript and its RegExp. Only that it works for me now.