A fork of https://github.com/crosspoint-reader/crosspoint-reader
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Erroneous navigation with long filenames in footnote links (#1723)

## Summary

* **What is the goal of this PR?**
* Increase the allowed link length for footnotes
* **What changes are included?**
* Un-magic-numbers parts of the footnote parser
* Increases max href length

## Additional Context

* Additional RAM usage was not noticable to me, worst case 16 * 128 * 2
= 4KB instead of previously 16 * 88 * 2 ~ 2.8KB, see #1031
* Motivation: My book navigated me to the start of the footnote chapter,
which required manual navigating for every footnote due to ungodly file
name choices which pushed the required href length to 72, which caused
truncating, which caused Crosspoint to not find the anchor (Sacred and
Terrible Air, available via reddit)

---

### AI Usage

While CrossPoint doesn't have restrictions on AI tools in contributing,
please be transparent about their usage as it
helps set the right context for reviewers.

Did you use AI tools to help write this code? _**NO**_

authored by

CSCMe and committed by
GitHub
8154f88d 56d3ab92

+16 -14
+5 -2
lib/Epub/Epub/FootnoteEntry.h
··· 2 2 3 3 #include <cstring> 4 4 5 + #define FOOTNOTE_NUMBER_LEN 32 6 + #define FOOTNOTE_HREF_LEN 96 7 + 5 8 struct FootnoteEntry { 6 - char number[24]; 7 - char href[64]; 9 + char number[FOOTNOTE_NUMBER_LEN]; 10 + char href[FOOTNOTE_HREF_LEN]; 8 11 9 12 FootnoteEntry() { 10 13 number[0] = '\0';
+1 -1
lib/Epub/Epub/Section.cpp
··· 10 10 #include "parsers/ChapterHtmlSlimParser.h" 11 11 12 12 namespace { 13 - constexpr uint8_t SECTION_FILE_VERSION = 20; 13 + constexpr uint8_t SECTION_FILE_VERSION = 21; 14 14 constexpr uint32_t HEADER_SIZE = sizeof(uint8_t) + sizeof(int) + sizeof(float) + sizeof(bool) + sizeof(uint8_t) + 15 15 sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint16_t) + sizeof(bool) + sizeof(bool) + 16 16 sizeof(uint8_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t);
+9 -9
lib/Epub/Epub/parsers/ChapterHtmlSlimParser.cpp
··· 539 539 } 540 540 self->insideFootnoteLink = true; 541 541 self->footnoteLinkDepth = self->depth; 542 - strncpy(self->currentFootnoteLinkHref, href, sizeof(self->currentFootnoteLinkHref) - 1); 543 - self->currentFootnoteLinkHref[sizeof(self->currentFootnoteLinkHref) - 1] = '\0'; 544 - self->currentFootnoteLinkText[0] = '\0'; 542 + strncpy(self->currentFootnote.href, href, sizeof(self->currentFootnote.href) - 1); 543 + self->currentFootnote.href[sizeof(self->currentFootnote.href) - 1] = '\0'; 544 + self->currentFootnote.number[0] = '\0'; 545 545 self->currentFootnoteLinkTextLen = 0; 546 546 547 547 // Apply underline style to visually indicate the link ··· 720 720 } 721 721 722 722 // Extract footnote link text 723 - for (int i = start; (self->currentFootnoteLinkTextLen < sizeof(self->currentFootnoteLinkText) - 1) && (i <= end); 723 + for (int i = start; (self->currentFootnoteLinkTextLen < sizeof(self->currentFootnote.number) - 1) && (i <= end); 724 724 ++i) { 725 - self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen++] = s[i]; 725 + self->currentFootnote.number[self->currentFootnoteLinkTextLen++] = s[i]; 726 726 } 727 - self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen] = '\0'; 727 + self->currentFootnote.number[self->currentFootnoteLinkTextLen] = '\0'; 728 728 } 729 729 730 730 for (int i = 0; i < len; i++) { ··· 915 915 916 916 // Closing a footnote link — create entry from collected text and href 917 917 if (self->insideFootnoteLink && self->depth == self->footnoteLinkDepth) { 918 - if (self->currentFootnoteLinkText[0] != '\0' && self->currentFootnoteLinkHref[0] != '\0') { 918 + if (self->currentFootnote.number[0] != '\0' && self->currentFootnote.href[0] != '\0') { 919 919 FootnoteEntry entry; 920 - strncpy(entry.number, self->currentFootnoteLinkText, sizeof(entry.number) - 1); 920 + strncpy(entry.number, self->currentFootnote.number, sizeof(entry.number) - 1); 921 921 entry.number[sizeof(entry.number) - 1] = '\0'; 922 - strncpy(entry.href, self->currentFootnoteLinkHref, sizeof(entry.href) - 1); 922 + strncpy(entry.href, self->currentFootnote.href, sizeof(entry.href) - 1); 923 923 entry.href[sizeof(entry.href) - 1] = '\0'; 924 924 int wordIndex = 925 925 self->wordsExtractedInBlock + (self->currentTextBlock ? static_cast<int>(self->currentTextBlock->size()) : 0);
+1 -2
lib/Epub/Epub/parsers/ChapterHtmlSlimParser.h
··· 79 79 // Footnote link tracking 80 80 bool insideFootnoteLink = false; 81 81 int footnoteLinkDepth = -1; 82 - char currentFootnoteLinkText[24] = {}; 82 + FootnoteEntry currentFootnote = {}; 83 83 int currentFootnoteLinkTextLen = 0; 84 - char currentFootnoteLinkHref[64] = {}; 85 84 std::vector<std::pair<int, FootnoteEntry>> pendingFootnotes; // <wordIndex, entry> 86 85 int wordsExtractedInBlock = 0; 87 86