From f13808939b9ae6d8d467538d17157a87e8a1a37c Mon Sep 17 00:00:00 2001 From: Kornel Benko Date: Thu, 18 May 2023 18:07:40 +0200 Subject: [PATCH] Advaced search: check for toString() before using it. (#12783) --- src/Paragraph.cpp | 2 +- src/insets/Inset.h | 2 ++ src/insets/InsetBranch.h | 2 ++ src/insets/InsetCitation.h | 2 ++ src/insets/InsetCounter.h | 2 ++ src/insets/InsetHyperlink.h | 2 ++ src/insets/InsetIPAMacro.h | 2 ++ src/insets/InsetQuotes.h | 2 ++ src/insets/InsetRef.h | 2 ++ src/insets/InsetSpace.h | 2 ++ src/insets/InsetSpecialChar.h | 2 ++ src/insets/InsetText.h | 2 ++ 12 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index b8819fdf1b..fed5a741ee 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -4314,7 +4314,7 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options, const Out else if (c == META_INSET && (options & AS_STR_INSETS)) { if (c == META_INSET && (options & AS_STR_PLAINTEXT)) { LASSERT(runparams != nullptr, return docstring()); - if (runparams->find_effective()) + if (runparams->find_effective() && getInset(i)->hasToString()) getInset(i)->toString(os); else getInset(i)->plaintext(os, *runparams); diff --git a/src/insets/Inset.h b/src/insets/Inset.h index fa9214d705..0ee6b12685 100644 --- a/src/insets/Inset.h +++ b/src/insets/Inset.h @@ -348,6 +348,8 @@ public: /// paragraph closes. this is appropriate e.g. for floats. virtual docstring xhtml(XMLStream &, OutputParams const &) const; + /// + virtual bool hasToString() const { return false; } /// Writes a string representation of the inset to the odocstream. /// This one should be called when you want the whole contents of /// the inset. diff --git a/src/insets/InsetBranch.h b/src/insets/InsetBranch.h index 6106ce5a5c..16e5524e23 100644 --- a/src/insets/InsetBranch.h +++ b/src/insets/InsetBranch.h @@ -80,6 +80,8 @@ private: /// docstring xhtml(XMLStream &, OutputParams const &) const override; /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// void forOutliner(docstring &, size_t const, bool const) const override; diff --git a/src/insets/InsetCitation.h b/src/insets/InsetCitation.h index 0adf0d4c3a..56ad45a9b6 100644 --- a/src/insets/InsetCitation.h +++ b/src/insets/InsetCitation.h @@ -62,6 +62,8 @@ public: /// docstring xhtml(XMLStream &, OutputParams const &) const override; /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// void forOutliner(docstring &, size_t const, bool const) const override; diff --git a/src/insets/InsetCounter.h b/src/insets/InsetCounter.h index 92d6f5b061..eb6338dde2 100644 --- a/src/insets/InsetCounter.h +++ b/src/insets/InsetCounter.h @@ -43,6 +43,8 @@ public: /// docstring xhtml(XMLStream &, OutputParams const &) const override; /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// void validate(LaTeXFeatures & features) const override; diff --git a/src/insets/InsetHyperlink.h b/src/insets/InsetHyperlink.h index 974f2f431a..59615b0d5b 100644 --- a/src/insets/InsetHyperlink.h +++ b/src/insets/InsetHyperlink.h @@ -34,6 +34,8 @@ public: /// bool isInToc() const override { return true; } /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// void forOutliner(docstring &, size_t const, bool const) const override; diff --git a/src/insets/InsetIPAMacro.h b/src/insets/InsetIPAMacro.h index 3305e6bf6e..5855da9e95 100644 --- a/src/insets/InsetIPAMacro.h +++ b/src/insets/InsetIPAMacro.h @@ -154,6 +154,8 @@ public: /// docstring xhtml(XMLStream &, OutputParams const &) const override; /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// void forOutliner(docstring &, size_t const, bool const) const override; diff --git a/src/insets/InsetQuotes.h b/src/insets/InsetQuotes.h index bebe9f1ec0..41bad175b8 100644 --- a/src/insets/InsetQuotes.h +++ b/src/insets/InsetQuotes.h @@ -154,6 +154,8 @@ public: /// docstring xhtml(XMLStream &, OutputParams const &) const override; + /// + bool hasToString() const override { return true; } /// void toString(odocstream &) const override; /// diff --git a/src/insets/InsetRef.h b/src/insets/InsetRef.h index 57377e1fd6..6286652f4d 100644 --- a/src/insets/InsetRef.h +++ b/src/insets/InsetRef.h @@ -65,6 +65,8 @@ public: /// docstring xhtml(XMLStream &, OutputParams const &) const override; /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// void forOutliner(docstring &, size_t const, bool const) const override; diff --git a/src/insets/InsetSpace.h b/src/insets/InsetSpace.h index e401d6d9ae..0b1bd7bfe5 100644 --- a/src/insets/InsetSpace.h +++ b/src/insets/InsetSpace.h @@ -136,6 +136,8 @@ public: /// void validate(LaTeXFeatures & features) const override; /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// void forOutliner(docstring &, size_t const, bool const) const override; diff --git a/src/insets/InsetSpecialChar.h b/src/insets/InsetSpecialChar.h index 0c8cc36304..36afa15fed 100644 --- a/src/insets/InsetSpecialChar.h +++ b/src/insets/InsetSpecialChar.h @@ -82,6 +82,8 @@ public: /// docstring xhtml(XMLStream &, OutputParams const &) const override; /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// bool isInToc() const override { return true; } diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h index bbff948c83..e271478114 100644 --- a/src/insets/InsetText.h +++ b/src/insets/InsetText.h @@ -180,6 +180,8 @@ public: /// void setMacrocontextPositionRecursive(DocIterator const & pos); /// + bool hasToString() const override { return true; } + /// void toString(odocstream &) const override; /// void forOutliner(docstring &, size_t const, bool const) const override; -- 2.39.5