File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,11 @@ def interpolate(string, values)
28
28
29
29
def interpolate_hash ( string , values )
30
30
pattern = INTERPOLATION_PATTERNS_CACHE [ config . interpolation_patterns ]
31
- string . gsub ( pattern ) do |match |
31
+ interpolated = false
32
+
33
+ interpolated_string = string . gsub ( pattern ) do |match |
34
+ interpolated = true
35
+
32
36
if match == '%%'
33
37
'%'
34
38
else
@@ -42,6 +46,8 @@ def interpolate_hash(string, values)
42
46
$3 ? sprintf ( "%#{ $3} " , value ) : value
43
47
end
44
48
end
49
+
50
+ interpolated ? interpolated_string : string
45
51
end
46
52
end
47
53
end
Original file line number Diff line number Diff line change @@ -65,9 +65,15 @@ def gsub(*args, &block)
65
65
end
66
66
67
67
end
68
+
68
69
test "with String subclass that redefined gsub method" do
69
70
assert_equal "Hello mars world" , I18n . interpolate ( RailsSafeBuffer . new ( "Hello %{planet} world" ) , :planet => 'mars' )
70
71
end
72
+
73
+ test "with String subclass that redefined gsub method returns same object if no interpolations" do
74
+ string = RailsSafeBuffer . new ( "Hello world" )
75
+ assert_same string , I18n . interpolate ( string , :planet => 'mars' )
76
+ end
71
77
end
72
78
73
79
class I18nMissingInterpolationCustomHandlerTest < I18n ::TestCase
You can’t perform that action at this time.
0 commit comments