Fixed #179 by converting placeholders before escaping @ signs.
This commit is contained in:
parent
74d7cb1d85
commit
e2c400ea6d
3 changed files with 13 additions and 5 deletions
|
@ -116,6 +116,9 @@ module Twine
|
|||
def format_value(value)
|
||||
value = value.dup
|
||||
|
||||
# convert placeholders (e.g. %@ -> %s)
|
||||
value = convert_placeholders_from_twine_to_android(value)
|
||||
|
||||
# capture xliff tags and replace them with a placeholder
|
||||
xliff_tags = []
|
||||
value.gsub! /<xliff:g.+?<\/xliff:g>/ do
|
||||
|
@ -133,9 +136,6 @@ module Twine
|
|||
value.sub! 'TWINE_XLIFF_TAG_PLACEHOLDER', xliff_tag
|
||||
end
|
||||
|
||||
# convert placeholders (e.g. %@ -> %s)
|
||||
value = convert_placeholders_from_twine_to_android(value)
|
||||
|
||||
# replace beginning and end spaces with \u0020. Otherwise Android strips them.
|
||||
value.gsub(/\A *| *\z/) { |spaces| '\u0020' * spaces.length }
|
||||
end
|
||||
|
|
|
@ -122,6 +122,10 @@ class TestAndroidFormatter < FormatterTest
|
|||
assert_equal "value\\u0020", @formatter.format_value('value ')
|
||||
end
|
||||
|
||||
def test_format_value_string_placeholder
|
||||
assert_equal "The file %s could not be found.", @formatter.format_value("The file %@ could not be found.")
|
||||
end
|
||||
|
||||
def test_format_value_escaping
|
||||
@escape_test_values.each do |input, expected|
|
||||
assert_equal expected, @formatter.format_value(input)
|
||||
|
|
|
@ -23,9 +23,13 @@ class PlaceholderTest < TwineTest
|
|||
Twine::Placeholders.convert_placeholders_from_twine_to_android(value)
|
||||
end
|
||||
|
||||
def test_replaces_string_placeholder
|
||||
def test_replaces_simple_string_placeholder
|
||||
assert_equal "some '%s' value", to_android("some '%@' value")
|
||||
end
|
||||
|
||||
def test_replaces_complicated_string_placeholder
|
||||
placeholder = placeholder('@')
|
||||
expected = placeholder
|
||||
expected = placeholder.dup
|
||||
expected[-1] = 's'
|
||||
assert_equal "some #{expected} value", to_android("some #{placeholder} value")
|
||||
end
|
||||
|
|
Reference in a new issue