commit 0f9f9be72d2001a1aca0bbc03d210d37a2a1100d
Author: Juergen Spitzmueller <[email protected]>
Date:   Wed Sep 30 10:03:56 2026 +0200

    When checking for existing labels from LaTeX (log), consider that they 
might have escaped characters
---
 src/Buffer.cpp | 9 +++++----
 src/Buffer.h   | 9 +++++++--
 src/LaTeX.cpp  | 4 ++--
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index c2d0107173..6332fd5d14 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -4253,19 +4253,20 @@ void Buffer::setInsetLabel(docstring const & label, 
InsetLabel const * il,
 
 
 InsetLabel const * Buffer::insetLabel(docstring const & label,
-                                     bool const active) const
+                                     bool const active, bool const escaped) 
const
 {
        for (auto const & rc : masterBuffer()->d->label_cache_) {
-               if (rc.label == label && (rc.active || !active))
+               docstring const lab = escaped ? escape(rc.label) : rc.label;
+               if (lab == label && (rc.active || !active))
                        return rc.inset;
        }
        return nullptr;
 }
 
 
-bool Buffer::activeLabel(docstring const & label) const
+bool Buffer::activeLabel(docstring const & label, bool const escaped) const
 {
-       return insetLabel(label, true) != nullptr;
+       return insetLabel(label, true, escaped) != nullptr;
 }
 
 
diff --git a/src/Buffer.h b/src/Buffer.h
index 9ee1f61842..220e2318d7 100644
--- a/src/Buffer.h
+++ b/src/Buffer.h
@@ -758,11 +758,16 @@ public:
        /// \return the InsetLabel associated with this \p label string
        /// If \p active is true we only return active labels
        /// (see @ref activeLabel)
+       /// With \p escaped = true the \p label string is
+       /// escaped via support::escape()
        InsetLabel const * insetLabel(docstring const & label,
-                                     bool const active = false) const;
+                                     bool const active = false,
+                                     bool const escaped = false) const;
        /// \return true if this \param label is an active label.
        /// Inactive labels are currently deleted labels (in ct mode)
-       bool activeLabel(docstring const & label) const;
+       /// With \p escaped = true the \p label string is
+       /// escaped via support::escape()
+       bool activeLabel(docstring const & label, bool const escaped = false) 
const;
 
        /// return a list of all used branches (also in children)
        void getUsedBranches(std::list<docstring> &, bool const from_master = 
false) const;
diff --git a/src/LaTeX.cpp b/src/LaTeX.cpp
index aa289a723d..25c9afb618 100644
--- a/src/LaTeX.cpp
+++ b/src/LaTeX.cpp
@@ -1175,7 +1175,7 @@ int LaTeX::scanLogFile(TeXErrors & terr)
                                if (regex_match(ml_token, sub, undef_ref)) {
                                        string const ref = sub.str(1);
                                        Buffer const * buf = 
theBufferList().getBufferFromTmp(file.absFileName());
-                                       if (!buf || 
!buf->masterBuffer()->activeLabel(from_utf8(ref))) {
+                                       if (!buf || 
!buf->masterBuffer()->activeLabel(from_utf8(ref), true)) {
                                                
terr.insertRef(getLineNumber(ml_token), from_ascii("Reference undefined"),
                                                        from_utf8(ml_token), 
child_name);
                                                retval |= UNDEF_UNKNOWN_REF;
@@ -1189,7 +1189,7 @@ int LaTeX::scanLogFile(TeXErrors & terr)
                                if (regex_match(token, sub, undef_ref)) {
                                        string const ref = sub.str(1);
                                        Buffer const * buf = 
theBufferList().getBufferFromTmp(file.absFileName());
-                                       if (!buf || 
!buf->masterBuffer()->activeLabel(from_utf8(ref))) {
+                                       if (!buf || 
!buf->masterBuffer()->activeLabel(from_utf8(ref), true)) {
                                                
terr.insertRef(getLineNumber(token), from_ascii("Reference undefined"),
                                                        from_utf8(token), 
child_name);
                                                retval |= UNDEF_UNKNOWN_REF;
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to