[LyX/master] DocBook: fix crash with Linguistics example.

Thibaut Cuvelier tcuvelier at lyx.org
Sat Sep 19 18:18:56 UTC 2020


commit abed1f3e6e3654e60f5f4db877fc7f3c3180bbb2
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date:   Wed Sep 2 00:36:46 2020 +0200

    DocBook: fix crash with Linguistics example.
    
    This was due to Floating::docbookTag not returning anything with the floattype_ tableau. Another issue that happened with that document is that the standard library's isspace crashed for some characters. I therefore implemented a more efficient version of the part that required it, and inlined the definition of isspace (even though that part becomes irrespective of locale, but was that feature ever used?).
---
 src/Floating.cpp       |    4 ++++
 src/output_docbook.cpp |   14 ++++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/Floating.cpp b/src/Floating.cpp
index 19fbf5f..a610c73 100644
--- a/src/Floating.cpp
+++ b/src/Floating.cpp
@@ -98,6 +98,10 @@ string Floating::docbookTag(bool hasTitle) const
 		// TODO: no good translation for now! Figures are the closest match, as they can contain text.
 		// Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
 		return "figure";
+	} else {
+		// If nothing matches, return something that will not be valid.
+		LYXERR0("Unrecognised float type: " + floattype_);
+		return "float";
 	}
 }
 
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 087d5a9..28d2e1e 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -427,6 +427,16 @@ void makeBibliography(
 }
 
 
+bool isNotOnlySpace(docstring const & str)
+{
+	for (auto const & c: str) {
+		if (c != ' ' && c != '\t' && c != '\n' && c != '\v' && c != '\f' && c != '\r')
+			return true;
+	}
+	return false;
+}
+
+
 void makeParagraph(
 		Text const & text,
 		Buffer const & buf,
@@ -518,8 +528,8 @@ void makeParagraph(
 	auto nextpar = par;
 	++nextpar;
 	auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end, special_case);
-	for (auto & parXML : pars) {
-		if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) {
+	for (docstring const & parXML : pars) {
+		if (isNotOnlySpace(parXML)) {
 			if (open_par)
 				openParTag(xs, &*par, prevpar);
 


More information about the lyx-cvs mailing list