mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #27693 from kenta-s/improve-to_sentence-method
Fix unexpected behavior of `to_sentence` with $,
This commit is contained in:
commit
a4dbbde4c9
2 changed files with 11 additions and 1 deletions
|
@ -60,7 +60,7 @@ module ActionView #:nodoc:
|
||||||
when 2
|
when 2
|
||||||
safe_join([array[0], array[1]], options[:two_words_connector])
|
safe_join([array[0], array[1]], options[:two_words_connector])
|
||||||
else
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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 three", to_sentence(["one", "two", "three"], last_word_connector: " ")
|
||||||
assert_equal "one, two and three", to_sentence(["one", "two", "three"], last_word_connector: " and ")
|
assert_equal "one, two and three", to_sentence(["one", "two", "three"], last_word_connector: " and ")
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue