[latex3-commits] [git/LaTeX3-latex3-latex3] master: Correct handling of detokenized keys (fixes #594) (af96e4446)

Joseph Wright joseph.wright at morningstar2.co.uk
Sat Jun 22 14:01:37 CEST 2019


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/af96e444613e25d072a3a789664d6ffd3ff0dc12

>---------------------------------------------------------------

commit af96e444613e25d072a3a789664d6ffd3ff0dc12
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sat Jun 22 13:01:06 2019 +0100

    Correct handling of detokenized keys (fixes #594)


>---------------------------------------------------------------

af96e444613e25d072a3a789664d6ffd3ff0dc12
 l3kernel/l3keys.dtx              | 40 +++++++++++++++++++++++++++++++++++-----
 l3kernel/testfiles/m3keys001.lvt |  9 ++++++++-
 l3kernel/testfiles/m3keys001.tlg |  6 ++++++
 3 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index 511d1fd9b..880932c43 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -1346,7 +1346,8 @@
   {
     \@@_property_find:n {#1}
     \cs_if_exist:cTF { \c_@@_props_root_tl \l_@@_property_tl }
-      { \@@_define_code:n {#2} }
+      { \@@_define_code:n {#2}
+      }
       {
          \tl_if_empty:NF \l_@@_property_tl
            {
@@ -1386,7 +1387,7 @@
               {
                 \tl_if_empty:NF \l_@@_module_tl
                   { \l_@@_module_tl  / }
-                #1
+               \tl_trim_spaces:n {#1}
               }
             \tl_set:Nn \l_@@_property_tl { . #2 }
           }
@@ -1436,7 +1437,7 @@
       { \use:c { \c_@@_props_root_tl \l_@@_property_tl } {#1} }
   }
 \exp_last_unbraced:NNNNo
-  \cs_new:Npn \__keys_define_code:w #1 \c_colon_str #2 \q_stop
+  \cs_new:Npn \@@_define_code:w #1 \c_colon_str #2 \q_stop
     { \tl_if_empty:nTF {#2} }
 %    \end{macrocode}
 % \end{macro}
@@ -2680,12 +2681,41 @@
 % \end{macro}
 %
 % \begin{macro}[EXP]{\@@_trim_spaces:n}
-%   Used in a few places so worth handling as a dedicated function.
+% \begin{macro}[EXP]
+%   {
+%     \@@_trim_spaces_auxi:w   ,
+%     \@@_trim_spaces_auxii:w  ,
+%     \@@_trim_spaces_auxiii:w
+%   }
+%   Space stripping has to allow for the fact that the key here might have
+%   several parts, and spaces need to be stripped from each part.
 %    \begin{macrocode}
 \cs_new:Npn \@@_trim_spaces:n #1
-  { \tl_trim_spaces:o { \tl_to_str:n {#1} } }
+  {
+    \exp_after:wN \@@_trim_spaces_auxi:w \tl_to_str:n {#1}
+      / \q_nil \q_stop
+    
+  }
+\cs_new:Npn \@@_trim_spaces_auxi:w #1 / #2 \q_stop
+  {
+    \quark_if_nil:nTF {#2}
+      { \tl_trim_spaces:n {#1} }
+      { \@@_trim_spaces_auxii:w #1 / #2 }
+  }
+\cs_new:Npn \@@_trim_spaces_auxii:w #1 / #2 / \q_nil
+  {
+    \tl_trim_spaces:n {#1}
+    \@@_trim_spaces_auxiii:w #2 / \q_recursion_tail / \q_recursion_stop
+  }
+\cs_set:Npn \@@_trim_spaces_auxiii:w #1 /
+  {
+    \quark_if_recursion_tail_stop:n {#1}
+    \tl_trim_spaces:n { / #1 }
+    \@@_trim_spaces_auxiii:w
+  }
 %    \end{macrocode}
 % \end{macro}
+% \end{macro}
 %
 % \begin{macro}[EXP,pTF]{\keys_if_exist:nn}
 %   A utility for others to see if a key exists.
diff --git a/l3kernel/testfiles/m3keys001.lvt b/l3kernel/testfiles/m3keys001.lvt
index 46995b97d..3984ee19f 100644
--- a/l3kernel/testfiles/m3keys001.lvt
+++ b/l3kernel/testfiles/m3keys001.lvt
@@ -1,4 +1,4 @@
-% Copyright (C) 2013,2015,2018 The LaTeX3 Project
+% Copyright (C) 2013,2015,2018,2019 The LaTeX3 Project
 
 
 \documentclass{minimal}
@@ -299,4 +299,11 @@
     \keys_set:nn { } { key }
   }
 
+\TEST { Spaces~after~detokenization }
+  {
+    \keys_define:nn { module } 
+      { \test .code:n = \TYPE { You~typed~"#1" } }
+    \keys_set:nn { module } { \test = Hello~World! }
+  }
+
 \END
diff --git a/l3kernel/testfiles/m3keys001.tlg b/l3kernel/testfiles/m3keys001.tlg
index f552eca97..cd404ba78 100644
--- a/l3kernel/testfiles/m3keys001.tlg
+++ b/l3kernel/testfiles/m3keys001.tlg
@@ -159,3 +159,9 @@ Defining key key on line ...
 <recently read> }
 l. ...  }
 ============================================================
+============================================================
+TEST 12: Spaces after detokenization
+============================================================
+Defining key module/\test on line ...
+You typed "Hello World!"
+============================================================





More information about the latex3-commits mailing list