Skip to content

Commit 44747db

Browse files
committed
Fix another crash on whitespace #191
1 parent d413895 commit 44747db

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/Html2OpenXml/Expressions/TextExpression.cs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public override IEnumerable<OpenXmlElement> Interpret (ParsingContext context)
101101
text = " " + text;
102102
}
103103
else if (startsWithSpace && prevIsPhrasing
104+
&& node.PreviousSibling!.TextContent.Length > 0
104105
&& !node.PreviousSibling!.TextContent[node.PreviousSibling.TextContent.Length - 1].IsWhiteSpaceCharacter())
105106
{
106107
text = " " + text;

test/HtmlToOpenXml.Tests/WhitespaceTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void ConsecutiveDivs_ReturnsMultipleParagraphs ()
4040
[TestCase("<span> Hello\r\n\r\nWorld! </span>")]
4141
[TestCase("<div><u>Hello World! </u></div>")]
4242
[TestCase("<hr>\n <span>Hello World!</span>")]
43+
[TestCase("<p><span></span> Hello World!</p>")]
4344
public void Multiline_ReturnsCollapsedText (string html)
4445
{
4546
var elements = converter.Parse(html);

0 commit comments

Comments
 (0)