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

HTML injection fails if the resource contains a commented-out <html> tag #346

Open
mbmoris opened this issue Oct 27, 2023 · 1 comment
Open
Labels
bug Something isn't working wontfix This will not be worked on

Comments

@mbmoris
Copy link

mbmoris commented Oct 27, 2023

Bug Report

The book is not browsable in any way

What happened?

The book is opened, the first page with the cover is displayed, but:

  • the pages counter is not displayed at the bottom of the screen
  • it is not possible to change page or jump to a specific chapter.

Expected behavior

Change page or jump to a specific chapter.

How to reproduce?

Open the attached sample book

Environment

  • Readium version: 2.6.0

Development environment

  • MacOS 14.0
  • Xcode 15.0.1

Testing device

  • iPhone13 iOS17

Additional context

bc40f3213719eae78585313877e66a9e4e3678.epub.zip

  • Are you willing to fix the problem and contribute a pull request? No
@mickael-menu
Copy link
Member

This is caused by the same issue I described on Slack for the Kotlin toolkit: https://readium.slack.com/archives/C703MSTQU/p1698229085820339?thread_ts=1698225175.649879&cid=C703MSTQU

The issue is that the book contains commented-out tags:

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<!--
<!DOCTYPE html>
-->

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" >

<!--
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" dir="ltr">
-->

But when we inject our own styles and scripts, we do it with regexes to locate the <html tags, so you get false positives in this case. Ideally we would use a proper HTML parser, but we decided to stay as close to the original source as possible when we modify it.

This is unlikely the core maintainers will tackle this fringe issue, but we would welcome a contribution to fix it. Maybe with a more complex regex you could handle that.

It's located here, if you want to give it a go: https://github.com/readium/kotlin-toolkit/blob/482ab0c2d759b4484762b0b823a953cc66661259/readium/navigator/src/main/java/org/readium/r2/navigator/epub/css/ReadiumCss.kt#L239

With the Swift toolkit, the regex is located here:

startRegex = NSRegularExpression("<\(tag)[^>]*>", options: [.caseInsensitive, .dotMatchesLineSeparators])

I'll keep the issue opened but like I said, it's unlikely I will tackle this anytime soon. So a contribution is most welcome!

@mickael-menu mickael-menu changed the title TestApp: The book is not browsable HTML injection fails if the resource contains a commented-out <html> tag Oct 27, 2023
@mickael-menu mickael-menu added bug Something isn't working wontfix This will not be worked on labels Oct 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants