actionpack 2.3.7 → 2.3.8.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionpack might be problematic. Click here for more details.

data/CHANGELOG CHANGED
@@ -1,3 +1,8 @@
1
+ *2.3.8 (May 24, 2010)*
2
+
3
+ * HTML safety: fix compatibility *without* the optional rails_xss plugin.
4
+
5
+
1
6
  *2.3.7 (May 24, 2010)*
2
7
 
3
8
  * HTML safety: fix compatibility with the optional rails_xss plugin. [Nathan Weizenbaum, Santiago Pastorino]
data/Rakefile CHANGED
@@ -79,7 +79,7 @@ spec = Gem::Specification.new do |s|
79
79
  s.has_rdoc = true
80
80
  s.requirements << 'none'
81
81
 
82
- s.add_dependency('activesupport', '= 2.3.7' + PKG_BUILD)
82
+ s.add_dependency('activesupport', '= 2.3.8' + PKG_BUILD)
83
83
  s.add_dependency('rack', '~> 1.1.0')
84
84
 
85
85
  s.require_path = 'lib'
@@ -2,7 +2,7 @@ module ActionPack #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 2
4
4
  MINOR = 3
5
- TINY = 7
5
+ TINY = 8
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -124,7 +124,7 @@ module ActionView
124
124
 
125
125
  # Use an alternate output buffer for the duration of the block.
126
126
  # Defaults to a new empty string.
127
- def with_output_buffer(buf = ActiveSupport::SafeBuffer.new) #:nodoc:
127
+ def with_output_buffer(buf = '') #:nodoc:
128
128
  self.output_buffer, old_buffer = buf, output_buffer
129
129
  yield
130
130
  output_buffer
@@ -3,17 +3,21 @@ require 'action_view/helpers/tag_helper'
3
3
  module ActionView
4
4
  module Helpers
5
5
  module TranslationHelper
6
- # Delegates to I18n#translate but also performs two additional functions. First, it'll catch MissingTranslationData exceptions
6
+ # Delegates to I18n#translate but also performs two additional functions. First, it'll catch MissingTranslationData exceptions
7
7
  # and turn them into inline spans that contains the missing key, such that you can see in a view what is missing where.
8
8
  #
9
9
  # Second, it'll scope the key by the current partial if the key starts with a period. So if you call translate(".foo") from the
10
10
  # people/index.html.erb template, you'll actually be calling I18n.translate("people.index.foo"). This makes it less repetitive
11
11
  # to translate many keys within the same partials and gives you a simple framework for scoping them consistently. If you don't
12
12
  # prepend the key with a period, nothing is converted.
13
- def translate(key, options = {})
14
- options[:raise] = true
15
- translation = I18n.translate(scope_key_by_partial(key), options)
16
- (translation.respond_to?(:join) ? translation.join : translation).html_safe
13
+ def translate(keys, options = {})
14
+ options[:raise] = true
15
+ are_keys_a_string = keys.is_a?(String)
16
+ keys = scope_keys_by_partial(keys)
17
+
18
+ translations = I18n.translate(keys, options)
19
+ translations = html_safe_translation_keys(keys, Array.wrap(translations))
20
+ are_keys_a_string ? translations.first : translations
17
21
  rescue I18n::MissingTranslationData => e
18
22
  keys = I18n.send(:normalize_translation_keys, e.locale, e.key, e.options[:scope])
19
23
  content_tag('span', keys.join(', '), :class => 'translation_missing')
@@ -28,12 +32,19 @@ module ActionView
28
32
 
29
33
 
30
34
  private
31
- def scope_key_by_partial(key)
32
- strkey = key.respond_to?(:join) ? key.join : key.to_s
33
- if strkey.first == "."
34
- template.path_without_format_and_extension.gsub(%r{/_?}, ".") + strkey
35
- else
36
- key
35
+ def scope_keys_by_partial(keys)
36
+ Array.wrap(keys).map do |key|
37
+ if key.to_s.first == "."
38
+ template.path_without_format_and_extension.gsub(%r{/_?}, ".") + key.to_s
39
+ else
40
+ key
41
+ end
42
+ end
43
+ end
44
+
45
+ def html_safe_translation_keys(keys, translations)
46
+ keys.zip(translations).map do |key, translation|
47
+ key =~ /(\b|_|\.)html$/ ? translation.html_safe : translation
37
48
  end
38
49
  end
39
50
  end
@@ -13,6 +13,11 @@ module ActionView
13
13
  def compile(template)
14
14
  magic = $1 if template.source =~ /\A(<%#.*coding[:=]\s*(\S+)\s*-?%>)/
15
15
  erb = "#{magic}<% __in_erb_template=true %>#{template.source}"
16
+
17
+ if erb.respond_to?(:force_encoding)
18
+ erb.force_encoding(template.source.encoding)
19
+ end
20
+
16
21
  ::ERB.new(erb, nil, erb_trim_mode, '@output_buffer').src
17
22
  end
18
23
  end
@@ -53,7 +53,7 @@ module ActionView
53
53
  setup :setup_with_controller
54
54
  def setup_with_controller
55
55
  @controller = TestController.new
56
- @output_buffer = ''.html_safe
56
+ @output_buffer = ''
57
57
  @rendered = ''
58
58
 
59
59
  self.class.send(:include_helper_modules!)
@@ -1,7 +1,7 @@
1
- $:.unshift(File.dirname(__FILE__) + '/../lib')
2
- $:.unshift(File.dirname(__FILE__) + '/../../activesupport/lib')
3
- $:.unshift(File.dirname(__FILE__) + '/fixtures/helpers')
4
- $:.unshift(File.dirname(__FILE__) + '/fixtures/alternate_helpers')
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+ $:.unshift File.expand_path('../../../activesupport/lib', __FILE__)
3
+ $:.unshift File.expand_path('../fixtures/helpers', __FILE__)
4
+ $:.unshift File.expand_path('../fixtures/alternate_helpers', __FILE__)
5
5
 
6
6
  require 'rubygems'
7
7
  require 'yaml'
@@ -58,4 +58,4 @@ class DummyMutex
58
58
  end
59
59
  end
60
60
 
61
- ActionController::Reloader.default_lock = DummyMutex.new
61
+ ActionController::Reloader.default_lock = DummyMutex.new
@@ -36,7 +36,7 @@ class CaptureTest < ActionController::TestCase
36
36
 
37
37
  def test_simple_capture
38
38
  get :capturing
39
- assert_equal "Dreamy days", @response.body.strip
39
+ assert_equal "<p>Dreamy days</p>", @response.body.strip
40
40
  end
41
41
 
42
42
  def test_content_for
@@ -1 +1 @@
1
- <%= t(['foo', 'bar']) %>
1
+ <% translation = t(['foo', 'bar', 'baz_html']) %><%= translation.first %>, <%= translation.second %>, <%= translation.third %>
@@ -1,4 +1,4 @@
1
1
  <% days = capture do %>
2
- Dreamy days
2
+ <p>Dreamy days</p>
3
3
  <% end %>
4
- <%= days %>
4
+ <%= days %>
@@ -1 +1 @@
1
- <%= t(['.foo', '.bar']) %>
1
+ <%= t(['.foo', '.bar']).join(", ") %>
@@ -0,0 +1 @@
1
+ <%= t('.helper') %>
@@ -1,32 +1,33 @@
1
1
  require 'abstract_unit'
2
2
 
3
- class TranslationHelperTest < Test::Unit::TestCase
3
+ class TranslationHelperTest < ActiveSupport::TestCase
4
4
  include ActionView::Helpers::TagHelper
5
5
  include ActionView::Helpers::TranslationHelper
6
-
6
+
7
7
  attr_reader :request
8
8
  def setup
9
9
  end
10
-
10
+
11
11
  def test_delegates_to_i18n_setting_the_raise_option
12
- I18n.expects(:translate).with(:foo, :locale => 'en', :raise => true).returns("")
12
+ I18n.expects(:translate).with([:foo], :locale => 'en', :raise => true).returns([""])
13
13
  translate :foo, :locale => 'en'
14
14
  end
15
-
15
+
16
16
  def test_returns_missing_translation_message_wrapped_into_span
17
17
  expected = '<span class="translation_missing">en, foo</span>'
18
18
  assert_equal expected, translate(:foo)
19
19
  end
20
-
20
+
21
21
  def test_translation_of_an_array
22
22
  I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(["foo", "bar"])
23
- assert_equal "foobar", translate(["foo", "bar"])
23
+ assert_equal ["foo", "bar"], translate(["foo", "bar"])
24
24
  end
25
25
 
26
26
  def test_translation_of_an_array_with_html
27
- expected = '<a href="#">foo</a><a href="#">bar</a>'
28
- I18n.expects(:translate).with(["foo", "bar"], :raise => true).returns(['<a href="#">foo</a>', '<a href="#">bar</a>'])
27
+ translate_expected = ['<a href="#">foo</a>', '<a href="#">bar</a>', '<a href="#">baz</a>']
28
+ I18n.expects(:translate).with(["foo", "bar", "baz_html"], :raise => true).returns(translate_expected)
29
29
  @view = ActionView::Base.new(ActionController::Base.view_paths, {})
30
+ expected = '<a href="#">foo</a>, <a href="#">bar</a>, <a href="#">baz</a>'
30
31
  assert_equal expected, @view.render(:file => "test/array_translation")
31
32
  end
32
33
 
@@ -35,16 +36,31 @@ class TranslationHelperTest < Test::Unit::TestCase
35
36
  I18n.expects(:localize).with(@time)
36
37
  localize @time
37
38
  end
38
-
39
+
39
40
  def test_scoping_by_partial
40
- expects(:template).returns(stub(:path_without_format_and_extension => "people/index"))
41
- I18n.expects(:translate).with("people.index.foo", :locale => 'en', :raise => true).returns("")
42
- translate ".foo", :locale => 'en'
41
+ I18n.expects(:translate).with(["test.translation.helper"], :raise => true).returns(["helper"])
42
+ @view = ActionView::Base.new(ActionController::Base.view_paths, {})
43
+ assert_equal "helper", @view.render(:file => "test/translation")
43
44
  end
44
45
 
45
46
  def test_scoping_by_partial_of_an_array
46
- I18n.expects(:translate).with("test.scoped_array_translation.foo.bar", :raise => true).returns(["foo", "bar"])
47
+ I18n.expects(:translate).with(["test.scoped_array_translation.foo", "test.scoped_array_translation.bar"], :raise => true).returns(["foo", "bar"])
47
48
  @view = ActionView::Base.new(ActionController::Base.view_paths, {})
48
- assert_equal "foobar", @view.render(:file => "test/scoped_array_translation")
49
+ assert_equal "foo, bar", @view.render(:file => "test/scoped_array_translation")
50
+ end
51
+
52
+ def test_translate_does_not_mark_plain_text_as_safe_html
53
+ I18n.expects(:translate).with(["hello"], :raise => true).returns(["Hello World"])
54
+ assert_equal false, translate("hello").html_safe?
55
+ end
56
+
57
+ def test_translate_marks_translations_named_html_as_safe_html
58
+ I18n.expects(:translate).with(["html"], :raise => true).returns(["<a>Hello World</a>"])
59
+ assert translate("html").html_safe?
60
+ end
61
+
62
+ def test_translate_marks_translations_with_a_html_suffix_as_safe_html
63
+ I18n.expects(:translate).with(["hello_html"], :raise => true).returns(["<a>Hello World</a>"])
64
+ assert translate("hello_html").html_safe?
49
65
  end
50
66
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: actionpack
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ prerelease: true
5
5
  segments:
6
6
  - 2
7
7
  - 3
8
- - 7
9
- version: 2.3.7
8
+ - 8
9
+ - pre1
10
+ version: 2.3.8.pre1
10
11
  platform: ruby
11
12
  authors:
12
13
  - David Heinemeier Hansson
@@ -27,8 +28,9 @@ dependencies:
27
28
  segments:
28
29
  - 2
29
30
  - 3
30
- - 7
31
- version: 2.3.7
31
+ - 8
32
+ - pre1
33
+ version: 2.3.8.pre1
32
34
  type: :runtime
33
35
  version_requirements: *id001
34
36
  - !ruby/object:Gem::Dependency
@@ -451,6 +453,7 @@ files:
451
453
  - test/fixtures/test/scoped_array_translation.erb
452
454
  - test/fixtures/test/sub_template_raise.html.erb
453
455
  - test/fixtures/test/template.erb
456
+ - test/fixtures/test/translation.erb
454
457
  - test/fixtures/test/update_element_with_capture.erb
455
458
  - test/fixtures/test/using_layout_around_block.html.erb
456
459
  - test/fixtures/test/using_layout_around_block_with_args.html.erb
@@ -508,11 +511,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
508
511
  version: "0"
509
512
  required_rubygems_version: !ruby/object:Gem::Requirement
510
513
  requirements:
511
- - - ">="
514
+ - - ">"
512
515
  - !ruby/object:Gem::Version
513
516
  segments:
514
- - 0
515
- version: "0"
517
+ - 1
518
+ - 3
519
+ - 1
520
+ version: 1.3.1
516
521
  requirements:
517
522
  - none
518
523
  rubyforge_project: actionpack