Skip to content

Commit 5776672

Browse files
authored
Merge pull request #204 from jafin/fix/innertext-table-whitespace-siblings
Fix GetInnerText skipping table tabs/newlines when HTML has whitespace between elements
2 parents 7396751 + 3979c6c commit 5776672

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
@@ -245,7 +245,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl
245245
}
246246
else if (elementStyle is not null && ((node is IHtmlTableCellElement && String.IsNullOrEmpty(elementStyle.GetDisplay())) || elementStyle.GetDisplay() == CssKeywords.TableCell))
247247
{
248-
if (node.NextSibling is IElement nextSibling)
248+
if (((IElement)node).NextElementSibling is IElement nextSibling)
249249
{
250250
var nextSiblingCss = ComputeCachedStyle(nextSibling, styleCollection, styleCache);
251251

@@ -257,7 +257,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl
257257
}
258258
else if (elementStyle is not null && ((node is IHtmlTableRowElement && String.IsNullOrEmpty(elementStyle.GetDisplay())) || elementStyle.GetDisplay() == CssKeywords.TableRow))
259259
{
260-
if (node.NextSibling is IElement nextSibling)
260+
if (((IElement)node).NextElementSibling is IElement nextSibling)
261261
{
262262
var nextSiblingCss = ComputeCachedStyle(nextSibling, styleCollection, styleCache);
263263

0 commit comments

Comments
 (0)