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

Regression in v3.3.1 with parsing nav element #94

Closed
majora2007 opened this issue May 19, 2023 · 4 comments
Closed

Regression in v3.3.1 with parsing nav element #94

majora2007 opened this issue May 19, 2023 · 4 comments

Comments

@majora2007
Copy link

I'm getting the following error upon opening the book, with options.

VersOne.Epub.Epub3NavException: EPUB parsing error: 'nav' element in the navigation file does not contain a required 'ol' element.
   at VersOne.Epub.Utils.TaskExtensionMethods.ExecuteAndUnwrapAggregateException[T](Task`1 task)
   at VersOne.Epub.Internal.BookRefReader.OpenBook(String filePath)
   at VersOne.Epub.EpubReader.OpenBook(String filePath, EpubReaderOptions epubReaderOptions)
PackageReaderOptions = new PackageReaderOptions
        {
            IgnoreMissingToc = true
        }

This was working prior to v3.3.0. Now it is throwing an exception.
Here is code from the nav.xhtml

<nav epub:type="toc" id="toc">
    <h1>Table of Contents</h1>
    <ol>
      <li>
        <a href="../Text/copyright.xhtml">Copyright</a>
      </li>
      <li>
        <a href="../Text/toc.xhtml">Contents</a>
      </li>
@vers-one
Copy link
Owner

Hmm, this <nav> element should be fine. Does the nav.xhtml file have other <nav>s by any chance?

@majora2007
Copy link
Author

Great find, yes there are!

@vers-one
Copy link
Owner

I added a few more parsing validations in EpubReader 3.3.0 to make Nullable reference type annotations possible. In case of Epub3Nav.Ol there were two options: I could make it nullable (i.e. Epub3NavOl? type) but that would be against the EPUB specification which says that there should be exactly one <ol> inside a <nav> and the applications would always have to check if its value is not null when they access this property. Or I could make it non-nullable (which aligns with the specification and which is what I chose to do) but the compiler immediately spotted that the parsed value can be null and raised an error. So the reason I added this parsing validation is to make sure that the Epub3Nav.Ol property will never get a null value.

I plan to add configuration options to control all validation checks but it will probably take a few weeks to implement all of them.

@majora2007
Copy link
Author

I for one, really enjoy the nullable support as I had ran into a few instances where I didn't expect something to be null and it was. I've subscribed to your configuration options issue. I will just update our wiki with some of the issues your library throws and how my users can fix it.

The amount of bad epubs is shocking. In Kavita, the software that uses this library, I have to balance the number of hacks to implement versus errors to throw. I've never seen a format so badly managed, even by the publishers themselves. Keys are never correct, missing toc, etc. It's just a mess.

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