Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to parse html that contains empty list element #161

Closed
can-oezkan opened this issue Sep 6, 2024 · 0 comments
Closed

Fails to parse html that contains empty list element #161

can-oezkan opened this issue Sep 6, 2024 · 0 comments

Comments

@can-oezkan
Copy link

can-oezkan commented Sep 6, 2024

Describe the bug
When trying to parse html that contains an empty list element:

<ul>
  <li>not empty</li>
  <li></li>
</ul>

an System.InvalidOperationException is thrown.

Stacktrace:

Unhandled exception. System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at HtmlToOpenXml.Expressions.ListExpression.<Interpret>d__4.MoveNext()
   at HtmlToOpenXml.Expressions.BlockElementExpression.ComposeChildren(ParsingContext context, IEnumerable`1 childNodes, ParagraphProperties paragraphProperties, Action`1 preAction, Action`1 postAction)
   at HtmlToOpenXml.Expressions.BlockElementExpression.Interpret(ParsingContext context, IEnumerable`1 childNodes)
   at HtmlToOpenXml.Expressions.PhrasingElementExpression.Interpret(ParsingContext context)
   at HtmlToOpenXml.Expressions.BlockElementExpression.Interpret(ParsingContext context)
   at HtmlToOpenXml.Expressions.BodyExpression.Interpret(ParsingContext context)
   at HtmlToOpenXml.HtmlConverter.<Parse>d__8.MoveNext()
   at HtmlToOpenXml.HtmlConverter.Parse(String html)
   at Program.<Main>$(String[] args) in C:\git\MyApp\MyApp\Program.cs:line 10

Expected behavior
An exception should not be thrown when the html contains an empty list element.

Repro

using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml;
using HtmlToOpenXml;

using var stream = new MemoryStream();
using var document = WordprocessingDocument.Create(stream, WordprocessingDocumentType.Document);

var converter = new HtmlConverter(document.AddMainDocumentPart());
    
converter.Parse("""
                      <ul>
                       <li>not empty</li>
                       <li></li>
                      </ul>
                      """);
@onizet onizet mentioned this issue Sep 24, 2024
@onizet onizet closed this as completed Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants