提交 55a5aac6 编写于 作者: J Javan Makhmali

Optimize Action Text's plain text conversion

Fixes that converting deeply nested elements could exceed the stack level.
上级 e5c143c4
...@@ -18,9 +18,11 @@ def plain_text_for_node(node, index = 0) ...@@ -18,9 +18,11 @@ def plain_text_for_node(node, index = 0)
end end
def plain_text_for_node_children(node) def plain_text_for_node_children(node)
node.children.each_with_index.map do |child, index| texts = []
plain_text_for_node(child, index) node.children.each_with_index do |child, index|
end.compact.join("") texts << plain_text_for_node(child, index)
end
texts.join("")
end end
def plain_text_method_for_node(node) def plain_text_method_for_node(node)
......
...@@ -73,6 +73,21 @@ class ActionText::PlainTextConversionTest < ActiveSupport::TestCase ...@@ -73,6 +73,21 @@ class ActionText::PlainTextConversionTest < ActiveSupport::TestCase
) )
end end
test "deeply nested tags are converted" do
assert_converted_to(
"Hello world!\nHow are you?",
ActionText::Fragment.wrap("<div>Hello world!</div><div></div>").tap do |fragment|
node = fragment.source.children.last
1_000.times do
child = node.clone
child.parent = node
node = child
end
node.inner_html = "How are you?"
end
)
end
test "preserves non-linebreak whitespace after text" do test "preserves non-linebreak whitespace after text" do
assert_converted_to( assert_converted_to(
"Hello world!", "Hello world!",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册