From f94c46a7454c50311654579c90108ea8de4ef07f Mon Sep 17 00:00:00 2001 From: naruse Date: Wed, 25 Jun 2008 04:44:32 +0000 Subject: [PATCH] * lib/erb.rb (ERB::Compiler:Buffer#new): push magic comment first. * lib/erb.rb (ERB::Compiler#compile): fix for broken input. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17569 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ lib/erb.rb | 9 ++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index c6abe7806f..36792b4f09 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jun 25 13:42:44 2008 NARUSE, Yui + + * lib/erb.rb (ERB::Compiler:Buffer#new): push magic comment first. + + * lib/erb.rb (ERB::Compiler#compile): fix for broken input. + Wed Jun 25 12:10:01 2008 NARUSE, Yui * lib/erb.rb (ERB::Compiler#compile): magic comment needs LF. diff --git a/lib/erb.rb b/lib/erb.rb index e1f0782855..d48d00ac3e 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -486,10 +486,10 @@ class ERB end class Buffer # :nodoc: - def initialize(compiler) + def initialize(compiler, enc=nil) @compiler = compiler @line = [] - @script = "" + @script = enc ? "#coding:#{enc.to_s}\n" : "" @compiler.pre_cmd.each do |x| push(x) end @@ -517,11 +517,10 @@ class ERB end def compile(s) - out = Buffer.new(self) - out.push("# -*- coding: #{s.encoding} -*-\n") + out = Buffer.new(self, s.encoding) content = '' - scanner = make_scanner(s) + scanner = make_scanner(s.dup.force_encoding("ASCII-8BIT")) scanner.scan do |token| if scanner.stag.nil? case token