Open wbzyl opened 13 years ago
I met same problem with rails template applications. https://gist.github.com/znz/5117644
How did you fix it?
I used
content = File.read(path, encoding: 'utf-8')
content.gsub! /"ほげ"/, '"ふが"'
File.open(path, 'wb') { |file| file.write(content) }
instead of
gsub_file "config/locales/hoge.yml", /"ほげ"/, '"ふが"'
I met same problem using append_to_file
, it seems File.binread
method return 'ASCII-8BIT' encoding string.
see: https://github.com/erikhuda/thor/blob/master/lib/thor/actions/inject_into_file.rb#L98
@bastengao , did you fix this somehow ?
On Version 0.19.4 - November 28, 2016
rvm/gems/ruby-2.2.1/gems/thor-0.19.4/lib/thor/actions
0.19.4/lib/thor/actions/inject_into_file.rb:95
content = File.binread(destination).force_encoding("utf-8") # jjff 2017-05-26
helped for me. It was trial and error, not knowing ruby and gems.
Seems to me that as general rule for textfiles, binread should always be avoided as utf-8 is certainly byte-oriented, but definitely not a byte-coding (character-points can span over several bytes)
Running:
on README with the content
yields
Responsible for this is error the file test.thor:
The above means that I can't gsub a chunk of text with the Polish diacritics in a html.erb file, for example.