Skip to content

Commit 6db6403

Browse files
Remove deprecated :rescue_format from exception handler
1 parent 1108de8 commit 6db6403

File tree

4 files changed

+3
-42
lines changed

4 files changed

+3
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
* Remove deprecated stuff:
66
- Setting `:default_exception_hander` Symbol to `I18n.exception_handler`.
77
- `normalize_translation_keys` in favor of `normalize_keys`.
8+
- `:rescue_format` option on the exception handler.

lib/i18n.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module I18n
99
autoload :Locale, 'i18n/locale'
1010
autoload :Tests, 'i18n/tests'
1111

12-
RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :throw, :raise, :rescue_format]
12+
RESERVED_KEYS = [:scope, :default, :separator, :resolve, :object, :fallback, :format, :cascade, :throw, :raise]
1313
RESERVED_KEYS_PATTERN = /%\{(#{RESERVED_KEYS.join("|")})\}/
1414

1515
extend(Module.new {

lib/i18n/exceptions.rb

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,7 @@ class ExceptionHandler
99
include Module.new {
1010
def call(exception, locale, key, options)
1111
if exception.is_a?(MissingTranslation)
12-
#
13-
# TODO: this block is to be replaced by `exception.message` when
14-
# rescue_format is removed
15-
if options[:rescue_format] == :html
16-
if !defined?(@rescue_format_deprecation)
17-
$stderr.puts "[DEPRECATED] I18n's :rescue_format option will be removed from a future release. All exception messages will be plain text. If you need the exception handler to return an html format please set or pass a custom exception handler."
18-
@rescue_format_deprecation = true
19-
end
20-
exception.html_message
21-
else
22-
exception.message
23-
end
24-
12+
exception.message
2513
elsif exception.is_a?(Exception)
2614
raise exception
2715
else
@@ -58,12 +46,6 @@ def initialize(locale, key, options = nil)
5846
options.each { |k, v| self.options[k] = v.inspect if v.is_a?(Proc) }
5947
end
6048

61-
def html_message
62-
key = CGI.escapeHTML titleize(keys.last)
63-
path = CGI.escapeHTML keys.join('.')
64-
%(<span class="translation_missing" title="translation missing: #{path}">#{key}</span>)
65-
end
66-
6749
def keys
6850
@keys ||= I18n.normalize_keys(locale, key, options[:scope]).tap do |keys|
6951
keys << 'no key' if keys.size < 2
@@ -78,13 +60,6 @@ def message
7860
def to_exception
7961
MissingTranslationData.new(locale, key, options)
8062
end
81-
82-
protected
83-
84-
# TODO : remove when #html_message is removed
85-
def titleize(key)
86-
key.to_s.gsub('_', ' ').gsub(/\b('?[a-z])/) { $1.capitalize }
87-
end
8863
end
8964

9065
include Base

test/i18n/exceptions_test.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,6 @@ def test_invalid_locale_stores_locale
2727
end
2828
end
2929

30-
test "MissingTranslationData html_message is a span with the titlelized last key token" do
31-
exception = I18n::MissingTranslationData.new(:de, :foo, :scope => :bar)
32-
assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', exception.html_message
33-
end
34-
35-
test "MissingTranslationData html_message html escapes key names" do
36-
exception = I18n::MissingTranslationData.new(:de, '<script>Evil</script>', :scope => '<iframe src="example.com" />')
37-
assert_equal '<span class="translation_missing" title="translation missing: de.&lt;iframe src=&quot;example.com&quot; /&gt;.&lt;script&gt;Evil&lt;/script&gt;">&lt;Script&gt;Evil&lt;/Script&gt;</span>', exception.html_message
38-
end
39-
40-
test "ExceptionHandler returns the html_message if :rescue_format => :html was given" do
41-
message = force_missing_translation_data(:rescue_format => :html)
42-
assert_equal '<span class="translation_missing" title="translation missing: de.bar.foo">Foo</span>', message
43-
end
44-
4530
test "InvalidPluralizationData stores entry and count" do
4631
force_invalid_pluralization_data do |exception|
4732
assert_equal [:bar], exception.entry

0 commit comments

Comments
 (0)