Skip to content

Commit 3979c6c

Browse files
committed
Fix GetInnerText skipping table tabs/newlines when HTML has whitespace between elements
Use NextElementSibling instead of NextSibling for table cell and row sibling checks, so whitespace text nodes between elements don't prevent tab/newline insertion.
1 parent 5a1d528 commit 3979c6c

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/AngleSharp.Css.Tests/Extensions/InnerText.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public void SetInnerText(String fixture, String expectedInnerText, String expect
4747
[TestCase("test1<br>test2<br>test3", "test1\ntest2\ntest3")]
4848
// table
4949
[TestCase("<table><tr><td>1</td><td>2</td></tr><tr><td>3</td><td>4</td></tr></table>", "1\t2\n3\t4")]
50+
[TestCase("<table><tr><td>1</td> <td>2</td></tr> <tr><td>3</td> <td>4</td></tr></table>", "1\t2\n3\t4")]
5051
[TestCase("<table><tr><td>1</td><td>2</td></tr><tr><td><table><tr><td>3</td><td>4</td></tr></table></td><td>5</td></tr></table>", "1\t2\n\n3\t4\n\t5")]
5152
// select
5253
[TestCase("<select><option>test1</option><option>test2</option></select>", "test1\ntest2")]

src/AngleSharp.Css/Extensions/ElementExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl
204204
}
205205
else if (elementStyle is not null && ((node is IHtmlTableCellElement && String.IsNullOrEmpty(elementStyle.GetDisplay())) || elementStyle.GetDisplay() == CssKeywords.TableCell))
206206
{
207-
if (node.NextSibling is IElement nextSibling)
207+
if (((IElement)node).NextElementSibling is IElement nextSibling)
208208
{
209209
var nextSiblingCss = nextSibling.ComputeCurrentStyle();
210210

@@ -216,7 +216,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl
216216
}
217217
else if (elementStyle is not null && ((node is IHtmlTableRowElement && String.IsNullOrEmpty(elementStyle.GetDisplay())) || elementStyle.GetDisplay() == CssKeywords.TableRow))
218218
{
219-
if (node.NextSibling is IElement nextSibling)
219+
if (((IElement)node).NextElementSibling is IElement nextSibling)
220220
{
221221
var nextSiblingCss = nextSibling.ComputeCurrentStyle();
222222

0 commit comments

Comments
 (0)