fix: Erroneous navigation with long filenames in footnote links (#1723)
This commit is contained in:
@@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#define FOOTNOTE_NUMBER_LEN 32
|
||||||
|
#define FOOTNOTE_HREF_LEN 96
|
||||||
|
|
||||||
struct FootnoteEntry {
|
struct FootnoteEntry {
|
||||||
char number[24];
|
char number[FOOTNOTE_NUMBER_LEN];
|
||||||
char href[64];
|
char href[FOOTNOTE_HREF_LEN];
|
||||||
|
|
||||||
FootnoteEntry() {
|
FootnoteEntry() {
|
||||||
number[0] = '\0';
|
number[0] = '\0';
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
#include "parsers/ChapterHtmlSlimParser.h"
|
#include "parsers/ChapterHtmlSlimParser.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
constexpr uint8_t SECTION_FILE_VERSION = 21;
|
constexpr uint8_t SECTION_FILE_VERSION = 22;
|
||||||
constexpr uint32_t HEADER_SIZE = sizeof(uint8_t) + // SECTION_FILE_VERSION
|
constexpr uint32_t HEADER_SIZE = sizeof(uint8_t) + // SECTION_FILE_VERSION
|
||||||
sizeof(int) + // fontId
|
sizeof(int) + // fontId
|
||||||
sizeof(float) + // lineCompression
|
sizeof(float) + // lineCompression
|
||||||
|
|||||||
@@ -742,9 +742,9 @@ void XMLCALL ChapterHtmlSlimParser::startElement(void* userData, const XML_Char*
|
|||||||
}
|
}
|
||||||
self->insideFootnoteLink = true;
|
self->insideFootnoteLink = true;
|
||||||
self->footnoteLinkDepth = self->depth;
|
self->footnoteLinkDepth = self->depth;
|
||||||
strncpy(self->currentFootnoteLinkHref, href, sizeof(self->currentFootnoteLinkHref) - 1);
|
strncpy(self->currentFootnote.href, href, sizeof(self->currentFootnote.href) - 1);
|
||||||
self->currentFootnoteLinkHref[sizeof(self->currentFootnoteLinkHref) - 1] = '\0';
|
self->currentFootnote.href[sizeof(self->currentFootnote.href) - 1] = '\0';
|
||||||
self->currentFootnoteLinkText[0] = '\0';
|
self->currentFootnote.number[0] = '\0';
|
||||||
self->currentFootnoteLinkTextLen = 0;
|
self->currentFootnoteLinkTextLen = 0;
|
||||||
|
|
||||||
// Apply underline style to visually indicate the link
|
// Apply underline style to visually indicate the link
|
||||||
@@ -985,11 +985,11 @@ void XMLCALL ChapterHtmlSlimParser::characterData(void* userData, const XML_Char
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Extract footnote link text
|
// Extract footnote link text
|
||||||
for (int i = start; (self->currentFootnoteLinkTextLen < sizeof(self->currentFootnoteLinkText) - 1) && (i <= end);
|
for (int i = start; (self->currentFootnoteLinkTextLen < sizeof(self->currentFootnote.number) - 1) && (i <= end);
|
||||||
++i) {
|
++i) {
|
||||||
self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen++] = s[i];
|
self->currentFootnote.number[self->currentFootnoteLinkTextLen++] = s[i];
|
||||||
}
|
}
|
||||||
self->currentFootnoteLinkText[self->currentFootnoteLinkTextLen] = '\0';
|
self->currentFootnote.number[self->currentFootnoteLinkTextLen] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
@@ -1220,11 +1220,11 @@ void XMLCALL ChapterHtmlSlimParser::endElement(void* userData, const XML_Char* n
|
|||||||
|
|
||||||
// Closing a footnote link — create entry from collected text and href
|
// Closing a footnote link — create entry from collected text and href
|
||||||
if (self->insideFootnoteLink && self->depth == self->footnoteLinkDepth) {
|
if (self->insideFootnoteLink && self->depth == self->footnoteLinkDepth) {
|
||||||
if (self->currentFootnoteLinkText[0] != '\0' && self->currentFootnoteLinkHref[0] != '\0') {
|
if (self->currentFootnote.number[0] != '\0' && self->currentFootnote.href[0] != '\0') {
|
||||||
FootnoteEntry entry;
|
FootnoteEntry entry;
|
||||||
strncpy(entry.number, self->currentFootnoteLinkText, sizeof(entry.number) - 1);
|
strncpy(entry.number, self->currentFootnote.number, sizeof(entry.number) - 1);
|
||||||
entry.number[sizeof(entry.number) - 1] = '\0';
|
entry.number[sizeof(entry.number) - 1] = '\0';
|
||||||
strncpy(entry.href, self->currentFootnoteLinkHref, sizeof(entry.href) - 1);
|
strncpy(entry.href, self->currentFootnote.href, sizeof(entry.href) - 1);
|
||||||
entry.href[sizeof(entry.href) - 1] = '\0';
|
entry.href[sizeof(entry.href) - 1] = '\0';
|
||||||
int wordIndex =
|
int wordIndex =
|
||||||
self->wordsExtractedInBlock + (self->currentTextBlock ? static_cast<int>(self->currentTextBlock->size()) : 0);
|
self->wordsExtractedInBlock + (self->currentTextBlock ? static_cast<int>(self->currentTextBlock->size()) : 0);
|
||||||
|
|||||||
@@ -113,9 +113,8 @@ class ChapterHtmlSlimParser {
|
|||||||
// Footnote link tracking
|
// Footnote link tracking
|
||||||
bool insideFootnoteLink = false;
|
bool insideFootnoteLink = false;
|
||||||
int footnoteLinkDepth = -1;
|
int footnoteLinkDepth = -1;
|
||||||
char currentFootnoteLinkText[24] = {};
|
FootnoteEntry currentFootnote = {};
|
||||||
int currentFootnoteLinkTextLen = 0;
|
int currentFootnoteLinkTextLen = 0;
|
||||||
char currentFootnoteLinkHref[64] = {};
|
|
||||||
std::vector<std::pair<int, FootnoteEntry>> pendingFootnotes; // <wordIndex, entry>
|
std::vector<std::pair<int, FootnoteEntry>> pendingFootnotes; // <wordIndex, entry>
|
||||||
int wordsExtractedInBlock = 0;
|
int wordsExtractedInBlock = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user