Skip to content

Commit

Permalink
Merge pull request rails#528 from lingceng/master
Browse files Browse the repository at this point in the history
Fix injecting into file which contains chinese
  • Loading branch information
rafaelfranca committed Feb 13, 2017
2 parents db16e19 + 2d20c6f commit 9b3495b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Session.vim
_yardoc
auto-save-list
coverage
doc/
/doc/
lib/bundler/man
pkg
pkg/*
Expand Down
2 changes: 1 addition & 1 deletion lib/thor/actions/inject_into_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def say_status(behavior)
#
def replace!(regexp, string, force)
return if base.options[:pretend]
content = File.binread(destination)
content = File.read(destination)
if force || !content.include?(replacement)
content.gsub!(regexp, string)
File.open(destination, "wb") { |file| file.write(content) }
Expand Down
5 changes: 5 additions & 0 deletions spec/actions/inject_into_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def file

expect(File.read(file)).to eq("__start__\nREADME\nmore content\nmore content\n__end__\n")
end

it "can insert chinese" do
invoke! "doc/README.zh", "\n中文", :after => "__start__"
expect(File.read(File.join(destination_root, "doc/README.zh"))).to eq("__start__\n中文\n说明\n__end__\n")
end
end

describe "#revoke!" do
Expand Down
3 changes: 3 additions & 0 deletions spec/fixtures/doc/README.zh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__start__
说明
__end__

0 comments on commit 9b3495b

Please sign in to comment.