Fix dynamic multi-byte utf-8 files rebuilding.

Thor compares the new contents with the existing file by using
File.binread(destination) == new_content.
File.binread returns a string with ASCII_8BIT encoding, which will not
match the new_content if new_content contains multi-byte utf-8.

This patch simply encodes the new_content to ASCII_8BIT before passing
it to Thor.
This commit is contained in:
Kevin McCarthy 2013-03-03 18:13:41 -08:00
parent de955aa0c3
commit 7608275089
3 changed files with 35 additions and 1 deletions

View file

@ -137,7 +137,7 @@ module Middleman::Cli
response = self.class.shared_rack.get(URI.escape(resource.destination_path))
if response.status == 200
create_file(output_file, response.body)
create_file(output_file, binary_encode(response.body))
else
handle_error(output_file, response.body)
end
@ -160,6 +160,13 @@ module Middleman::Cli
self.shell.error(response)
end
end
def binary_encode(string)
if string.respond_to?(:force_encoding)
string.force_encoding("ascii-8bit")
end
string
end
}
end