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

xml parser: fix regressions #584

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crengine/src/lvtinydom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ extern const int gDOMVersionCurrent = DOM_VERSION_CURRENT;

/// change in case of incompatible changes in swap/cache file format to avoid using incompatible swap file
// increment to force complete reload/reparsing of old file
#define CACHE_FILE_FORMAT_VERSION "3.05.74k"
#define CACHE_FILE_FORMAT_VERSION "3.05.75k"
/// increment following value to force re-formatting of old book after load
#define FORMATTING_VERSION_ID 0x0033

Expand Down
13 changes: 7 additions & 6 deletions crengine/src/lvxml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5737,11 +5737,11 @@ bool LVXMLParser::ReadText()
const lChar32 *begin = m_read_buffer + m_read_buffer_pos;
const lChar32 *ptr = begin;
const lChar32 *end = m_read_buffer + m_read_buffer_len;
const lChar32 *limit = m_read_buffer + (TEXT_SPLIT_SIZE + 1 - tlen);
const lChar32 *limit = m_read_buffer + (TEXT_SPLIT_SIZE - tlen);
if (limit > end)
limit = end;
// If m_eof (m_read_buffer_pos == m_read_buffer_len), this 'for' won't loop
for (; ptr < end; ++ptr) {
for (; ptr < limit; ++ptr) {
lChar32 ch = *ptr;
if ( m_in_cdata ) { // we're done only when we meet ']]>'
if ( ch==']' ) {
Expand Down Expand Up @@ -5811,21 +5811,21 @@ bool LVXMLParser::ReadText()
m_txt_buf.append( m_read_buffer + m_read_buffer_pos, ptr - begin);
m_read_buffer_pos = ptr - m_read_buffer;
}
if ( tlen > TEXT_SPLIT_SIZE || flgBreak || splitParas) {
if ( tlen >= TEXT_SPLIT_SIZE || flgBreak || splitParas) {
//=====================================================
// Provide accumulated text to callback
lChar32 * buf = m_txt_buf.modify();

int last_split_txtlen = tlen;
if (tlen > TEXT_SPLIT_SIZE) {
if (tlen >= TEXT_SPLIT_SIZE) {
for (const lChar32 *ptr = buf + m_txt_buf.length() - 1; ptr >= buf; --ptr) {
lChar32 ch = *ptr;
if (ch <= ' ') [[unlikely]] {
if (ch == ' ') {
// Not sure what this last_split_txtlen is about: may be to avoid spliting
// a word into multiple text nodes (when tlen > TEXT_SPLIT_SIZE), so splitting
// on spaces, \r and \n when giving the text to the callback?
last_split_txtlen = ptr - buf;
last_split_txtlen = ptr - buf + 1;
break;
} else if (ch == '\r' || ch == '\n') {
// Not sure what happens when \r\n at buffer boundary, and we would have \r at end
Expand All @@ -5836,7 +5836,8 @@ bool LVXMLParser::ReadText()
if (ptr < buf + m_txt_buf.length() - 1)
nextch = ptr[1];
if ((ch == '\r' && nextch != '\n') || (ch == '\n' && nextch != '\r')) {
last_split_txtlen = ptr - buf;
last_split_txtlen = ptr - buf + 1;
break;
}
}
}
Expand Down
Loading