mirror of https://github.com/rails/rails
Fix: simple_format with blank wrapper_tag option returns plain html tag.
By default `simple_format` method returns the text wrapped with `<p>`. But if we explicitly specify the `wrapper_tag: nil` in the options, it returns the text wrapped with `<></>` tag. Before: ```ruby simple_format("Hello World", {}, { wrapper_tag: nil }) # <>Hello World</> ``` After: ```ruby simple_format("Hello World", {}, { wrapper_tag: nil }) # <p>Hello World</p> ``` Co-authored-by: Junichi Ito <jit@sonicgarden.jp>
This commit is contained in:
parent
2fbb25b771
commit
1677e31240
|
@ -1,3 +1,24 @@
|
||||||
|
* Fix `simple_format` with blank `wrapper_tag` option returns plain html tag
|
||||||
|
|
||||||
|
By default `simple_format` method returns the text wrapped with `<p>`. But if we explicitly specify
|
||||||
|
the `wrapper_tag: nil` in the options, it returns the text wrapped with `<></>` tag.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
simple_format("Hello World", {}, { wrapper_tag: nil })
|
||||||
|
# <>Hello World</>
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
simple_format("Hello World", {}, { wrapper_tag: nil })
|
||||||
|
# <p>Hello World</p>
|
||||||
|
```
|
||||||
|
|
||||||
|
*Akhil G Krishnan*, *Junichi Ito*
|
||||||
|
|
||||||
* Don't double-encode nested `field_id` and `field_name` index values
|
* Don't double-encode nested `field_id` and `field_name` index values
|
||||||
|
|
||||||
Pass `index: @options` as a default keyword argument to `field_id` and
|
Pass `index: @options` as a default keyword argument to `field_id` and
|
||||||
|
|
|
@ -320,7 +320,7 @@ module ActionView
|
||||||
# simple_format("<a target=\"_blank\" href=\"http://example.com\">Continue</a>", {}, { sanitize_options: { attributes: %w[target href] } })
|
# simple_format("<a target=\"_blank\" href=\"http://example.com\">Continue</a>", {}, { sanitize_options: { attributes: %w[target href] } })
|
||||||
# # => "<p><a target=\"_blank\" href=\"http://example.com\">Continue</a></p>"
|
# # => "<p><a target=\"_blank\" href=\"http://example.com\">Continue</a></p>"
|
||||||
def simple_format(text, html_options = {}, options = {})
|
def simple_format(text, html_options = {}, options = {})
|
||||||
wrapper_tag = options.fetch(:wrapper_tag, :p)
|
wrapper_tag = options[:wrapper_tag] || "p"
|
||||||
|
|
||||||
text = sanitize(text, options.fetch(:sanitize_options, {})) if options.fetch(:sanitize, true)
|
text = sanitize(text, options.fetch(:sanitize_options, {})) if options.fetch(:sanitize, true)
|
||||||
paragraphs = split_paragraphs(text)
|
paragraphs = split_paragraphs(text)
|
||||||
|
|
|
@ -68,6 +68,7 @@ class TextHelperTest < ActionView::TestCase
|
||||||
|
|
||||||
def test_simple_format_with_custom_wrapper
|
def test_simple_format_with_custom_wrapper
|
||||||
assert_equal "<div></div>", simple_format(nil, {}, { wrapper_tag: "div" })
|
assert_equal "<div></div>", simple_format(nil, {}, { wrapper_tag: "div" })
|
||||||
|
assert_equal "<p></p>", simple_format(nil, {}, { wrapper_tag: nil })
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_simple_format_with_custom_wrapper_and_multi_line_breaks
|
def test_simple_format_with_custom_wrapper_and_multi_line_breaks
|
||||||
|
|
Loading…
Reference in New Issue