Merge pull request #27693 from kenta-s/improve-to_sentence-method

Fix unexpected behavior of `to_sentence` with $,
This commit is contained in:
Rafael França 2017-01-18 01:43:16 -05:00 committed by GitHub
commit a4dbbde4c9
2 changed files with 11 additions and 1 deletions

View File

@ -60,7 +60,7 @@ module ActionView #:nodoc:
when 2
safe_join([array[0], array[1]], options[:two_words_connector])
else
safe_join([safe_join(array[0...-1], options[:words_connector]), options[:last_word_connector], array[-1]])
safe_join([safe_join(array[0...-1], options[:words_connector]), options[:last_word_connector], array[-1]], nil)
end
end
end

View File

@ -92,4 +92,14 @@ class OutputSafetyHelperTest < ActionView::TestCase
assert_equal "one, two three", to_sentence(["one", "two", "three"], last_word_connector: " ")
assert_equal "one, two and three", to_sentence(["one", "two", "three"], last_word_connector: " and ")
end
test "to_sentence is not affected by $," do
$, = "|"
begin
assert_equal "one and two", to_sentence(["one", "two"])
assert_equal "one, two, and three", to_sentence(["one", "two", "three"])
ensure
$, = nil
end
end
end