Add escaping of symbols

This commit is contained in:
Simon Eskildsen
2013-08-30 12:31:57 -04:00
parent 40fba9ee6c
commit 0343f6dc94
2 changed files with 12 additions and 3 deletions
+4 -3
View File
@@ -24,9 +24,10 @@ module Liquid
private
def interpolate(name, vars)
name.gsub(/:(\w+)/) do
vars[$1.to_sym] or raise TranslationError, translate("errors.i18n.undefined_interpolation", :key => $1, :name => name)
end
name.gsub(/([^\\]):(\w+)/) {
raise TranslationError, translate("errors.i18n.undefined_interpolation", :key => $1, :name => name) unless vars[$2.to_sym]
"#{$1}#{vars[$2.to_sym]}"
}.gsub("\\:", ":")
end
def deep_fetch_translation(name)
+8
View File
@@ -34,4 +34,12 @@ class I18nTest < Test::Unit::TestCase
def test_sets_default_path_to_en
assert_equal I18n::DEFAULT_LOCALE, I18n.new.path
end
def test_escaping_of_symbols
assert_equal "do replaced! not :gsub", @i18n.send(:interpolate,
'do :replace not \\:gsub',
{
:replace => "replaced!"
})
end
end