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

Fix crash on following empty links #120

Merged
merged 1 commit into from Mar 9, 2018

Conversation

Projects
None yet
1 participant
@poire-z
Contributor

poire-z commented Mar 9, 2018

getCurrentPageLinks() (used when swipe to follow links is enabled) returns ldomXRange objects for links' content, that we can't build on empty links.
edit: elem->getChildNode(0); expects to have children, and it returns something (a node, widh id 32, so may be the root node) even when there is no child, which if (node) let pass - so it requires calling hasChildren() before calling getChildNode().

Solves the crash reported in koreader/koreader#3731.
For this book, it was caused by empty calibre tags with id for page changes (ala kepub I guess):

The next census, compiled <a epub:type="pagebreak" id="page12" class="calibre1"></a>in 2011 and published at the end of 2012

If it had content, we would get in KOReader (on this page, which has another valid footnote link):

a_xp: /body/DocFragment[6]/body/section/p[5]/sup/a/text().0
a_xp: /body/DocFragment[6]/body/section/p[6]/a/text().0
03/09/18-11:47:24 WARN  {
    [1] = {
        ["end_x"] = 179,
        ["a_xpointer"] = "/body/DocFragment[6]/body/section/p[5]/sup/a.0",
        ["end_y"] = 299,
        ["start_x"] = 172,
        ["section"] = "#_doc_fragment_24_ c02-f1",
        ["start_y"] = 299
    },
    [2] = {
        ["end_x"] = 250,
        ["a_xpointer"] = "/body/DocFragment[6]/body/section/p[6]/a.0",
        ["end_y"] = 367,
        ["start_x"] = 232,
        ["uri"] = "",
        ["start_y"] = 367
    }
}

This empty link has no href= attribute, so it would get empty uri (external link) or section (internal link) key, and would be discarded in the follow page link candidates.
Could be a problem on empty links that have a href=, but as we wouldn't see them anyway on the page, it's fine (and would prevent following an invisible link when swiping left, expecting to go to next page).

Fix crash on following empty links
getCurrentPageLinks() (used when swipe to follow links is enabled)
returns ldomXRange objects for links' content, that we can't build
on empty links.

@poire-z poire-z merged commit 9978b3a into koreader:master Mar 9, 2018

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details

@poire-z poire-z deleted the poire-z:fix_crash_on_empty_links branch Mar 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment