Skip to content

Commit 9c80829

Browse files
authored
fix error in pooled node list code (#39)
1 parent fc83fbe commit 9c80829

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

native/html5ever_nif/src/flat_dom.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ impl<T> PoolOrVec<T> where T: Clone {
6262
*len += 1;
6363
},
6464
val @ PoolOrVec::Pool { .. } => {
65-
*val = PoolOrVec::Vec {
66-
vec: vec![item],
67-
};
65+
if let PoolOrVec::Pool { head, len } = val {
66+
let mut vec = pool[*head..(*head + *len)].to_owned();
67+
vec.push(item);
68+
*val = PoolOrVec::Vec {
69+
vec: vec,
70+
};
71+
} else {
72+
unreachable!()
73+
}
6874
},
6975
PoolOrVec::Vec { vec } => {
7076
vec.push(item);

test/html5ever_test.exs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,84 @@ defmodule Html5everTest do
6767
html = String.duplicate("<div>", 100)
6868
assert {:ok, _} = Html5ever.flat_parse(html)
6969
end
70+
71+
test "reasonably deep html" do
72+
html = """
73+
<!doctype html>
74+
<html>
75+
<head>
76+
<title>Test</title>
77+
</head>
78+
<body>
79+
<div class="content">
80+
<span>
81+
<div>
82+
<span>
83+
<small>
84+
very deep content
85+
</small>
86+
</span>
87+
</div>
88+
<img src="file.jpg" />
89+
</span>
90+
</div>
91+
</body>
92+
</html>
93+
"""
94+
95+
parsed = Html5ever.parse(html)
96+
97+
assert {:ok,
98+
[
99+
{:doctype, "html", "", ""},
100+
{"html", [],
101+
[
102+
{"head", [], ["\n", " ", {"title", [], ["Test"]}, "\n", " "]},
103+
"\n",
104+
" ",
105+
{"body", [],
106+
[
107+
"\n",
108+
" ",
109+
{"div", [{"class", "content"}],
110+
[
111+
"\n",
112+
" ",
113+
{"span", [],
114+
[
115+
"\n",
116+
" ",
117+
{"div", [],
118+
[
119+
"\n",
120+
" ",
121+
{"span", [],
122+
[
123+
"\n",
124+
" ",
125+
{"small", [],
126+
["\n", " very deep content", "\n", " "]},
127+
"\n",
128+
" "
129+
]},
130+
"\n",
131+
" "
132+
]},
133+
"\n",
134+
" ",
135+
{"img", [{"src", "file.jpg"}], []},
136+
"\n",
137+
" "
138+
]},
139+
"\n",
140+
" "
141+
]},
142+
"\n",
143+
" ",
144+
"\n",
145+
"\n"
146+
]}
147+
]}
148+
]} = parsed
149+
end
70150
end

0 commit comments

Comments
 (0)