[latex3-commits] [git/latex3] master: Make \IfBooleanTF robust against multi-token arguments (fix #422) (fad7d2e)

Bruno Le Floch bruno at le-floch.fr
Wed Dec 6 01:01:36 CET 2017


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

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

commit fad7d2e29a7b055ad4cbdfee7b6de2bd5bc7f3cb
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Tue Dec 5 19:01:36 2017 -0500

    Make \IfBooleanTF robust against multi-token arguments (fix #422)
    
    Previously \IfBooleanTF was a copy of \bool_if:NTF but that would break
    if given an empty argument or a multi-token argument.  Now these misuses
    are detected.


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

fad7d2e29a7b055ad4cbdfee7b6de2bd5bc7f3cb
 l3packages/xparse/testfiles/xparse004.luatex.tlg |   57 ++++++++++++++++++++++
 l3packages/xparse/testfiles/xparse004.lvt        |    7 +++
 l3packages/xparse/testfiles/xparse004.tlg        |   57 ++++++++++++++++++++++
 l3packages/xparse/xparse.dtx                     |   27 ++++++++--
 4 files changed, 143 insertions(+), 5 deletions(-)

diff --git a/l3packages/xparse/testfiles/xparse004.luatex.tlg b/l3packages/xparse/testfiles/xparse004.luatex.tlg
index ed45fe2..227d6d4 100644
--- a/l3packages/xparse/testfiles/xparse004.luatex.tlg
+++ b/l3packages/xparse/testfiles/xparse004.luatex.tlg
@@ -1973,3 +1973,60 @@ TEST 27: Non-character token delimiters
 *************************************************
 something/-NoValue-
 ============================================================
+============================================================
+TEST 28: IfBoolean multi token
+============================================================
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "xparse/if-boolean"
+! 
+! Invalid use \IfBooleanTF {}
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+| 
+| The first argument of \IfBoolean(TF/T/F) must be a boolean argument obtained
+| from parsing 's' or 't' arguments.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "xparse/if-boolean"
+! 
+! Invalid use \IfBooleanTF {}
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+| 
+| The first argument of \IfBoolean(TF/T/F) must be a boolean argument obtained
+| from parsing 's' or 't' arguments.
+|...............................................
+FALSE
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "xparse/if-boolean"
+! 
+! Invalid use \IfBooleanTF {\ERROR \ERROR }
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+| 
+| The first argument of \IfBoolean(TF/T/F) must be a boolean argument obtained
+| from parsing 's' or 't' arguments.
+|...............................................
+FALSE
+============================================================
diff --git a/l3packages/xparse/testfiles/xparse004.lvt b/l3packages/xparse/testfiles/xparse004.lvt
index 16f9272..707194f 100644
--- a/l3packages/xparse/testfiles/xparse004.lvt
+++ b/l3packages/xparse/testfiles/xparse004.lvt
@@ -455,4 +455,11 @@
       { \TYPE {#1/#2} }
     \foo \undefinedSecondArgument {something}
   }
+
+\TEST { IfBoolean~multi~token }
+  {
+    \IfBooleanT { } { \ERROR }
+    \IfBooleanTF { } { \ERROR } { \FALSE }
+    \IfBooleanF { \ERROR \ERROR } { \FALSE }
+  }
 \END
diff --git a/l3packages/xparse/testfiles/xparse004.tlg b/l3packages/xparse/testfiles/xparse004.tlg
index 4aa5c14..9592d03 100644
--- a/l3packages/xparse/testfiles/xparse004.tlg
+++ b/l3packages/xparse/testfiles/xparse004.tlg
@@ -1973,3 +1973,60 @@ TEST 27: Non-character token delimiters
 *************************************************
 something/-NoValue-
 ============================================================
+============================================================
+TEST 28: IfBoolean multi token
+============================================================
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "xparse/if-boolean"
+! 
+! Invalid use \IfBooleanTF {}
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+| 
+| The first argument of \IfBoolean(TF/T/F) must be a boolean argument obtained
+| from parsing 's' or 't' arguments.
+|...............................................
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "xparse/if-boolean"
+! 
+! Invalid use \IfBooleanTF {}
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+| 
+| The first argument of \IfBoolean(TF/T/F) must be a boolean argument obtained
+| from parsing 's' or 't' arguments.
+|...............................................
+FALSE
+!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+!
+! LaTeX error: "xparse/if-boolean"
+! 
+! Invalid use \IfBooleanTF {\ERROR \ERROR }
+! 
+! See the LaTeX3 documentation for further information.
+! 
+! For immediate help type H <return>.
+!...............................................  
+l. ...  }
+|'''''''''''''''''''''''''''''''''''''''''''''''
+| This is a coding error.
+| 
+| The first argument of \IfBoolean(TF/T/F) must be a boolean argument obtained
+| from parsing 's' or 't' arguments.
+|...............................................
+FALSE
+============================================================
diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 7dfc3d4..b810765 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -520,14 +520,14 @@
 %
 % \begin{function}[EXP]{\IfBooleanT, \IfBooleanF, \IfBooleanTF}
 %   \begin{syntax}
-%     \cs{IfBooleanTF} \meta{argument} \Arg{true code} \Arg{false code}
+%     \cs{IfBooleanTF} \Arg{argument} \Arg{true code} \Arg{false code}
 %   \end{syntax}
 %   Used to test if \meta{argument} (|#1|, |#2|, \emph{etc.}) is
 %   \cs{BooleanTrue} or \cs{BooleanFalse}. For example
 %   \begin{verbatim}
 %     \NewDocumentCommand \foo { s m }
 %       {
-%         \IfBooleanTF #1
+%         \IfBooleanTF {#1}
 %           { \DoSomethingWithStar {#2} }
 %           { \DoSomethingWithoutStar {#2} }
 %       }
@@ -4042,6 +4042,13 @@
     (or~no~arguments~at~all).~You~cannot~have~a~terminal~optional~
     argument~with~expandable~commands.
   }
+\__msg_kernel_new:nnnn { xparse } { if-boolean }
+  { Invalid~use~\iow_char:N\\IfBooleanTF~{#1} }
+  {
+    \c__msg_coding_error_text_tl
+    The~first~argument~of~\iow_char:N\\IfBoolean(TF/T/F)~must~be~
+    a~boolean~argument~obtained~from~parsing~'s'~or~'t'~arguments.
+  }
 \__msg_kernel_new:nnnn { xparse } { inconsistent-long }
   { Inconsistent~long~arguments~for~expandable~command~'#1'. }
   {
@@ -4377,9 +4384,19 @@
 %   normal \cs{c_true_bool} and \cs{c_false_bool}, so testing for them is
 %   done with the \cs{bool_if:NTF} functions from \textsf{l3prg}.
 %    \begin{macrocode}
-\cs_new_eq:NN \IfBooleanTF \bool_if:NTF
-\cs_new_eq:NN \IfBooleanT  \bool_if:NT
-\cs_new_eq:NN \IfBooleanF  \bool_if:NF
+\cs_new:Npn \IfBooleanTF #1
+  {
+    \bool_lazy_and:nnTF
+      { \tl_if_single_p:n {#1} }
+      { \tl_if_single_token_p:n #1 }
+      { \bool_if:NTF #1 }
+      {
+        \__msg_kernel_error:nnn { xparse } { if-boolean } {#1}
+        \use_ii:nn
+      }
+  }
+\cs_new:Npn \IfBooleanT #1#2 { \IfBooleanTF {#1} {#2} { } }
+\cs_new:Npn \IfBooleanF #1 { \IfBooleanTF {#1} { } }
 %    \end{macrocode}
 % \end{macro}
 %





More information about the latex3-commits mailing list