File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -48,7 +48,7 @@ def self.reserve_key(key)
48
48
end
49
49
50
50
def self . reserved_keys_pattern # :nodoc:
51
- @reserved_keys_pattern ||= /%\{ (#{ RESERVED_KEYS . join ( "|" ) } )\} /
51
+ @reserved_keys_pattern ||= /(?<!%) %\{ (#{ RESERVED_KEYS . join ( "|" ) } )\} /
52
52
end
53
53
54
54
module Base
Original file line number Diff line number Diff line change @@ -118,6 +118,24 @@ module Interpolation
118
118
assert_raises ( I18n ::ReservedInterpolationKey ) { interpolate ( :interpolate ) }
119
119
end
120
120
121
+ test "interpolation: it does not raise I18n::ReservedInterpolationKey for escaped variables" do
122
+ assert_nothing_raised do
123
+ assert_equal '%{separator}' , interpolate ( :foo => :bar , :default => '%%{separator}' )
124
+ end
125
+
126
+ # Note: The two interpolations below do not remove the escape character (%) because
127
+ # I18n should not alter the strings when no interpolation parameters are given,
128
+ # see the comment at the top of this file.
129
+ assert_nothing_raised do
130
+ assert_equal '%%{scope}' , interpolate ( :default => '%%{scope}' )
131
+ end
132
+
133
+ I18n . backend . store_translations ( :en , :interpolate => 'Hi %%{scope}!' )
134
+ assert_nothing_raised do
135
+ assert_equal 'Hi %%{scope}!' , interpolate ( :interpolate )
136
+ end
137
+ end
138
+
121
139
test "interpolation: deep interpolation for default string" do
122
140
assert_equal 'Hi %{name}!' , interpolate ( :default => 'Hi %{name}!' , :deep_interpolation => true )
123
141
end
You can’t perform that action at this time.
0 commit comments