From 6c777f8fe793e75f02db9f821f75a83ca13a6ccb Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 2 Jul 2022 09:07:53 +0200 Subject: [PATCH] GUI: result list paragraph format: avoid problems with input like - Document the fact that literal % characters need to be quoted as %% - Preserve the original input if the % substitution has no defined target. --- src/doc/user/usermanual.html | 55 ++++++++++++++++++++++-------------- src/doc/user/usermanual.xml | 37 ++++++++++++------------ src/utils/smallut.cpp | 13 ++++----- 3 files changed, 58 insertions(+), 47 deletions(-) diff --git a/src/doc/user/usermanual.html b/src/doc/user/usermanual.html index ee2aabfd..431dd18a 100644 --- a/src/doc/user/usermanual.html +++ b/src/doc/user/usermanual.html @@ -4989,9 +4989,22 @@ fs.inotify.max_user_watches=32768 -

This is an arbitrary HTML string where the - following printf-like % - substitutions will be performed:

+

This is an arbitrary HTML string which will be + transformed by printf-like % substitutions to show the + results.

+
+

Note

+

Any literal % + character in the input must be quoted as + %%. E.g. <table style="width: 100%;"> + should be entered as <table style="width: + 100%%;">.

+
+

The following substitutions will be performed:

+

In addition to the predefined values above, all + strings like %(fieldname) will be replaced by the + value of the field named fieldname for this document. Only + stored fields can be accessed in this way, the value + of indexed but not stored fields is not known at this + point in the search process (see field + configuration). There are currently very few + fields stored by default, apart from the values above + (only author and + filename), so this + feature will need some custom local configuration to + be useful. An example candidate would be the + recipient field which is + generated by the message input handlers.

The format of the Preview, Edit, and Snippets links is <a href="P%N">, <a @@ -5078,24 +5109,6 @@ fs.inotify.max_user_watches=32768 "link" href="#RCL.SEARCH.GUI.RUNSCRIPT" title= "3.2.5. Unix-like systems: running arbitrary commands on result files"> section about defining scripts.

-

In addition to the predefined values above, all - strings like %(fieldname) will be replaced by the - value of the field named fieldname for this document. Only - stored fields can be accessed in this way, the value - of indexed but not stored fields is not known at this - point in the search process (see field - configuration). There are currently very few - fields stored by default, apart from the values above - (only author and - filename), so this - feature will need some custom local configuration to - be useful. An example candidate would be the - recipient field which is - generated by the message input handlers.

The default value for the paragraph format string is:

diff --git a/src/doc/user/usermanual.xml b/src/doc/user/usermanual.xml
index d1b14cbb..aa2cbd8b 100644
--- a/src/doc/user/usermanual.xml
+++ b/src/doc/user/usermanual.xml
@@ -3667,9 +3667,13 @@ fs.inotify.max_user_watches=32768
           
             The paragraph format
 
-            This is an arbitrary HTML string where the following printf-like
-            % substitutions will be performed:
-
+            This is an arbitrary HTML string which will be transformed by printf-like
+              % substitutions to show the results.
+            Any literal % character in the input
+                must be quoted as %%. E.g.  <table style="width:
+                100%;"> should be entered as
+	        <table style="width: 100%%;">.
+            The following substitutions will be performed:
             
               
                 %AAbstract
@@ -3719,6 +3723,17 @@ fs.inotify.max_user_watches=32768
               
             
 
+            In addition to the predefined values above, all strings
+            like %(fieldname) will be replaced by the value of the field
+            named fieldname for this document. Only stored fields can be accessed
+            in this way, the value of indexed but not stored fields is not known at this point in
+            the search process (see field
+            configuration). There are currently very few fields stored by default, apart from
+            the values above (only author and filename), so
+            this feature will need some custom local configuration to be useful. An example
+            candidate would be the recipient field which is generated by the
+            message input handlers.
+
             The format of the Preview, Edit, and Snippets links is 
             <a href="P%N">,
             <a href="E%N">
@@ -3740,20 +3755,6 @@ fs.inotify.max_user_watches=32768
             embedded, the script will be started on the top-level parent).
             See the section about defining scripts.
 
-            In addition to the predefined values above, all strings
-            like %(fieldname) will be replaced by the
-            value of the field named fieldname for this
-            document. Only stored fields can be accessed in this way, the
-            value of indexed but not stored fields is not known at this
-            point in the search process
-            (see field configuration). There are currently very few fields
-            stored by default, apart from the values above
-            (only author
-            and filename), so this feature will need
-            some custom local configuration to be useful. An example
-            candidate would be the recipient field
-            which is generated by the message input handlers.
-
             The default value for the paragraph format string is:
             \n"
@@ -7103,7 +7104,7 @@ other = rclcat:other
         The right side of each assignment holds a command to be
         executed for opening the file. The following substitutions are
         performed: 
-
+        
         
           
             %D
diff --git a/src/utils/smallut.cpp b/src/utils/smallut.cpp
index 2fe7c963..1c5f2da0 100644
--- a/src/utils/smallut.cpp
+++ b/src/utils/smallut.cpp
@@ -611,12 +611,11 @@ bool pcSubst(const string& in, string& out, const map& subs)
                 out += '%';
                 continue;
             }
-            map::const_iterator tr;
-            if ((tr = subs.find(*it)) != subs.end()) {
+            auto tr = subs.find(*it);
+            if (tr != subs.end()) {
                 out += tr->second;
             } else {
-                // We used to do "out += *it;" here but this does not make
-                // sense
+                out += std::string("%") + *it;
             }
         } else {
             out += *it;
@@ -648,7 +647,7 @@ bool pcSubst(const string& in, string& out, const map& subs)
                 string::size_type j = in.find_first_of(')', i);
                 if (j == string::npos) {
                     // ??concatenate remaining part and stop
-                    out += in.substr(i - 2);
+                    out += std::string("%") + in.substr(i - 2);
                     break;
                 }
                 key = in.substr(i, j - i);
@@ -660,9 +659,7 @@ bool pcSubst(const string& in, string& out, const map& subs)
             if ((tr = subs.find(key)) != subs.end()) {
                 out += tr->second;
             } else {
-                // Substitute to nothing, that's the reasonable thing to do
-                // instead of keeping the %(key)
-                // out += key.size()==1? key : string("(") + key + string(")");
+                out += std::string("%") + (key.size()==1? key : string("(") + key + string(")"));
             }
         } else {
             out += in[i];