提交 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)
end
def plain_text_for_node_children(node)
node.children.each_with_index.map do |child, index|
plain_text_for_node(child, index)
end.compact.join("")
texts = []
node.children.each_with_index do |child, index|
texts << plain_text_for_node(child, index)
end
texts.join("")
end
def plain_text_method_for_node(node)
......
......@@ -73,6 +73,21 @@ class ActionText::PlainTextConversionTest < ActiveSupport::TestCase
)
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
assert_converted_to(
"Hello world!",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册