fukamachi / caveman

Lightweight web application framework for Common Lisp.
http://8arrow.org/caveman/
775 stars 63 forks source link

receive the file name is garbled when the file name has chinese character #62

Closed ly5156 closed 9 years ago

ly5156 commented 9 years ago

I select a file to upload, if the file name has chinese character , and the file name received will be garbled,I do not know why, and how to resolve it.

The file name is "黑客与画家(中文版).pdf" ,my code like this: Foreground code

<form action="/upload/file" method="post" enctype="multipart/form-data" 
accept-charset="UTF-8">
      <input name="file" type="file">
      <input type="submit">
      </form>

Background code

(defroute ("/upload/file" :method :POST) (&key |file|)
  (format t "~a~%" |file|)
  (maphash #'(lambda (key value) (format t "~a=~a~%" key value)) (second |file|))
  (maphash #'(lambda (key value) (format t "~a=~a~%" key value)) (third |file|))
  )

And the output

(#<FD-STREAM for "file /tmp/temp-q4xv5fjy" {1003C22E93}>
 #<HASH-TABLE :TEST EQUAL :COUNT 2 {1003C21283}>
 #<HASH-TABLE :TEST EQUAL :COUNT 2 {1003C20773}>)
name=file
filename=黑客与画家(中文版).pdf
content-disposition=form-data; name="file"; filename="黑客与画家(中文版).pdf"
content-type="application/octet-stream
fukamachi commented 9 years ago

Thank you for reporting.

fast-http's multipart-parser uses xsubseq:coerce-to-string for converting header values and it seems it assumes the octets is ASCII.

https://github.com/fukamachi/fast-http/blob/master/src/fast-http.lisp#L266

Replacing it by Babel would be fixed this. Needs more tests and should be fixed soon.

ly5156 commented 9 years ago

Thank you for your answer. That very helpful to me.