itchyny / calendar.vim

A calendar application for Vim
MIT License
1.95k stars 72 forks source link

iconv() failed? #61

Closed kamichidu closed 9 years ago

kamichidu commented 9 years ago

It's enrolled in Google Calendar as "文化の日" on Nov. 3, but "文化の日" is displayed with "<95><89>". I use kaoriya gvim 7.4.444 under Windows 7, with set enc=utf8.

kamichidu commented 9 years ago

iconv('文化の日', 'utf8', 'cp932') returns "<95><89><82> ". Something are related?

itchyny commented 9 years ago

What is the encoding of the downloaded file?

kamichidu commented 9 years ago

It's "cp932". Can I check anything else?

itchyny commented 9 years ago

That might be the problem. I remember that calendar.vim assumes that the response file is encoded in "utf-8". Which do you use curl or wget? If both are available, calendar.vim uses curl. The problem is that it downloads with cp932.

kamichidu commented 9 years ago

Maybe curl is used since I can use curl and wget, both.

itchyny commented 9 years ago

I tested on Windows 7, curl (with the version following) but it downloads the events with utf-8. I think that Google Calendar api always returns the response in utf-8.

curl 7.39.0 (i386-pc-win32) libcurl/7.39.0 OpenSSL/1.0.1j zlib/1.2.8
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtsp
smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile NTLM SSL libz

What is your curl version? Can you investigate why it downloads with cp932? Opening calendar with :Calendar -debug keeps the response files and please check the encoding of .cache/calendar.vim/download/google_calendar_download_2014baabaa. If it is in cp932, curl actually downloads with cp932 so it is to be blame, if it is in utf-8, calendar.vim mistakenly saves the response to cp932 and reads it assuming utf-8.

kamichidu commented 9 years ago

curl -version output is pasted below, and response files have I checked response files generated by Calendar -debug, encodings in each header are UTF-8.

curl 7.27.0 (i386-pc-win32) libcurl/7.27.0 OpenSSL/1.0.0j zlib/1.2.7 libidn/1.18 libssh2/1.4.2 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap pop3 pop3s rtmp rtsp scp sftp smtp smtps telnet tftp
Features: AsynchDNS GSS-Negotiate IDN Largefile NTLM SSL SSPI libz

I investigated a reason of this issue.

  1. &enc is 'cp932' at the first time, later, I changed &enc 'cp932' to 'utf8'. (Sorry, I forgot it.)
  2. calendar.vim wrote to file using &enc (writefile() in autoload/calendar/cache.vim), and read from file using &enc.

I think this issue is very rare-case, and it works correctly after I delete ~/.cache/calendar.vim/.

itchyny commented 9 years ago

Ok. I close this issue. Note that holiday calendars are downloaded only once because they will rarely updated.

kamichidu commented 9 years ago

Thanks!

itchyny commented 9 years ago

Thank you for investigation.

itchyny commented 9 years ago

(This is a note for myself) This issue is caused by changing &enc; when the app writes the file and reads the file. While the external downloader saves in utf-8, writefile() saves in &enc. This issue is actually a bug but occurs rarely. If this happens, delete the cache directory.