From 3979c6c9818248fa97fecd7e99e3051ff16d43ba Mon Sep 17 00:00:00 2001 From: Jason Finch Date: Sat, 28 Mar 2026 21:14:57 +1000 Subject: [PATCH] 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. --- src/AngleSharp.Css.Tests/Extensions/InnerText.cs | 1 + src/AngleSharp.Css/Extensions/ElementExtensions.cs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/AngleSharp.Css.Tests/Extensions/InnerText.cs b/src/AngleSharp.Css.Tests/Extensions/InnerText.cs index f12fb38..5c1044d 100644 --- a/src/AngleSharp.Css.Tests/Extensions/InnerText.cs +++ b/src/AngleSharp.Css.Tests/Extensions/InnerText.cs @@ -47,6 +47,7 @@ public void SetInnerText(String fixture, String expectedInnerText, String expect [TestCase("test1
test2
test3", "test1\ntest2\ntest3")] // table [TestCase("
12
34
", "1\t2\n3\t4")] + [TestCase("
1 2
3 4
", "1\t2\n3\t4")] [TestCase("
12
34
5
", "1\t2\n\n3\t4\n\t5")] // select [TestCase("", "test1\ntest2")] diff --git a/src/AngleSharp.Css/Extensions/ElementExtensions.cs b/src/AngleSharp.Css/Extensions/ElementExtensions.cs index cc25785..a0a358e 100644 --- a/src/AngleSharp.Css/Extensions/ElementExtensions.cs +++ b/src/AngleSharp.Css/Extensions/ElementExtensions.cs @@ -204,7 +204,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl } else if (elementStyle is not null && ((node is IHtmlTableCellElement && String.IsNullOrEmpty(elementStyle.GetDisplay())) || elementStyle.GetDisplay() == CssKeywords.TableCell)) { - if (node.NextSibling is IElement nextSibling) + if (((IElement)node).NextElementSibling is IElement nextSibling) { var nextSiblingCss = nextSibling.ComputeCurrentStyle(); @@ -216,7 +216,7 @@ private static void ItcInCssBox(ICssStyleDeclaration elementStyle, ICssStyleDecl } else if (elementStyle is not null && ((node is IHtmlTableRowElement && String.IsNullOrEmpty(elementStyle.GetDisplay())) || elementStyle.GetDisplay() == CssKeywords.TableRow)) { - if (node.NextSibling is IElement nextSibling) + if (((IElement)node).NextElementSibling is IElement nextSibling) { var nextSiblingCss = nextSibling.ComputeCurrentStyle();