diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-06-01 12:33:49 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-06-01 12:34:08 -0700 |
commit | 94911c7af7f2e1da0a23d64d2055b77bc1f6ece8 (patch) | |
tree | 72c5ee6df180bdc1a9009be10feae8ccff940800 /actionpack/lib | |
parent | 9537fd0e3a7625afe4bee75d749647ca1837195a (diff) | |
download | rails-94911c7af7f2e1da0a23d64d2055b77bc1f6ece8.tar.gz rails-94911c7af7f2e1da0a23d64d2055b77bc1f6ece8.tar.bz2 rails-94911c7af7f2e1da0a23d64d2055b77bc1f6ece8.zip |
Ensure ERB source begins with the encoding comment
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/template/handlers/erb.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/template/template.rb | 6 |
2 files changed, 8 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/template/handlers/erb.rb b/actionpack/lib/action_view/template/handlers/erb.rb index d773df7d29..21272ef089 100644 --- a/actionpack/lib/action_view/template/handlers/erb.rb +++ b/actionpack/lib/action_view/template/handlers/erb.rb @@ -16,7 +16,9 @@ module ActionView self.default_format = Mime::HTML def compile(template) - ::ERB.new("<% __in_erb_template=true %>#{template.source}", nil, erb_trim_mode, '@output_buffer').src + magic = $1 if template.source =~ /\A(<%#.*coding:\s*(\S+)\s*-?%>)/ + erb = "#{magic}<% __in_erb_template=true %>#{template.source}" + ::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src end end end diff --git a/actionpack/lib/action_view/template/template.rb b/actionpack/lib/action_view/template/template.rb index a9897258d2..e7ea42c2eb 100644 --- a/actionpack/lib/action_view/template/template.rb +++ b/actionpack/lib/action_view/template/template.rb @@ -53,7 +53,11 @@ module ActionView locals_code = locals.keys.map! { |key| "#{key} = local_assigns[:#{key}];" }.join code = @handler.call(self) - encoding_comment = $1 if code.sub!(/\A(#.*coding.*)\n/, '') + if code.sub!(/\A(#.*coding.*)\n/, '') + encoding_comment = $1 + elsif defined?(Encoding) && Encoding.respond_to?(:default_external) + encoding_comment = "#coding:#{Encoding.default_external}" + end source = <<-end_src def #{method_name}(local_assigns) |