From 1cb67ebf2a0563d69609ab3c267d0878e63c63bd Mon Sep 17 00:00:00 2001 From: bbshelper Date: Thu, 25 Jul 2024 13:15:24 +0800 Subject: [PATCH] xml parser: fix regressions - in 40082dcf, limit was not applied - in 9d70a2e5, - loop should terminate if a qualified newline is encountered - last_split_txtlen should take the space/newline into account --- crengine/src/lvxml.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crengine/src/lvxml.cpp b/crengine/src/lvxml.cpp index 564c441c0..bc21b7b58 100644 --- a/crengine/src/lvxml.cpp +++ b/crengine/src/lvxml.cpp @@ -5741,7 +5741,7 @@ bool LVXMLParser::ReadText() 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==']' ) { @@ -5825,7 +5825,7 @@ bool LVXMLParser::ReadText() // 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 @@ -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; } } }