奇怪的字符编码 [英] Weird Characters encoding
问题描述
而不是1个特殊字符,我有2个字符:普通字母+口音。
参数:{ name="Mylène.png,_cardbiz_session=>be1d5b7a2f27c7c4979ac4c16fe8fc82,authenticity_token=>9vmJ02DjgKYCpoBNUcWwUlpxDXA8ddcoALHXyT6wrnM =,asset=> {file=>#& ActionDispatch :: Http :: UploadedFile:0x007f94d38d37d0 @ original_filename =Mylène.png,@ content_type =image / png,@ headers =Content-Disposition:form-data; name = \asset [file] \ ; filename = \Myle\xCC\x80ne.png\\r\\\
Content-Type:image / png\r\\\
,@ tempfile =#<文件:/ var / folders / q5 / yvy_v9bn5wl_s5ccy_35qsmw0000gn / T / RackMultipart20130805-51100-1eh07dp> >},id="copie-de-sm}
:
- logger.debug file_name
- logger.debug file_name.chars.map(&) to_s).inspect
每次相同的结果:
- Mylène
- [M,y,l,e,,n,e]
当我尝试使用文件名作为匹配器,已经存在的名称正确编码为utf-8时,您会看到我的问题;)
- 编码是utf-8到处。
- 在ruby 1.9.3和rails 3.2.14下工作。
- 在任何涉及的文件中添加了#encoding:utf-8。
作为一个想法,接受它!
我也在这里发表了一个问题: https://github.com/carrierwaveuploader/carrierwave/issues/1185 ,但不知道它的载波波问题还是我丢失的东西...
似乎要链接到MACOSX。
https://www.ruby- forum.com/topic/4407424 解释它,并提及 https://bugs.ruby -lang.org/issues/7267 了解更多详细信息和问题。
MACOSX将特殊字符分解为 utf8-mac ,而不是 utf-8 ...
虽然您无法知道文件名的编码,但只是预先确定。
感谢我们的Linux人员在哪里工作正常。 ;)
file_name.encode!('utf-8','utf-8-mac')。chars.map &:to_s)
I have a weird behaviour in my params whichare passed as utf-8 but the special characters are not well managed. Instead of 1 special character, I have 2 characters: the normal letter + the accent.
Parameters: {"name"=>"Mylène.png", "_cardbiz_session"=>"be1d5b7a2f27c7c4979ac4c16fe8fc82", "authenticity_token"=>"9vmJ02DjgKYCpoBNUcWwUlpxDXA8ddcoALHXyT6wrnM=", "asset"=>{"file"=># < ActionDispatch::Http::UploadedFile:0x007f94d38d37d0 @original_filename="Mylène.png", @content_type="image/png", @headers="Content-Disposition: form-data; name=\"asset[file]\"; filename=\"Myle\xCC\x80ne.png\"\r\nContent-Type: image/png\r\n", @tempfile=# < File:/var/folders/q5/yvy_v9bn5wl_s5ccy_35qsmw0000gn/T/RackMultipart20130805-51100-1eh07dp > >}, "id"=>"copie-de-sm"}
I log this:
- logger.debug file_name
- logger.debug file_name.chars.map(&:to_s).inspect
Each time, same result:
- Mylène
- ["M", "y", "l", "e", "̀", "n", "e"]
As i try to use the filename as a matcher with already existing names properly encoded utf-8, you see my problem ;)
- Encodings are utf-8 everywhere.
- working under ruby 1.9.3 and rails 3.2.14.
- Added #encoding: utf-8 in top of any file involved.
I anyone as an idea, take it !
I also published an Issue here : https://github.com/carrierwaveuploader/carrierwave/issues/1185 but not sure if its a carrierwave issue or me missing something...
Seems to be linked to MACOSX.
https://www.ruby-forum.com/topic/4407424 explains it and refers to https://bugs.ruby-lang.org/issues/7267 for more details and discution.
MACOSX decomposing special characters into utf8-mac instead of utf-8...
While you can't know the encoding of a file name, just presupose it.
Thanks to our Linux guy where it works properly. ;)
file_name.encode!('utf-8', 'utf-8-mac').chars.map(&:to_s)
这篇关于奇怪的字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!