[latex3-commits] [git/LaTeX3-latex3-latex3] cs-delimited-args: Disallow implicit begin/end-group tokens as open delimiters (dd0062fa6)

PhelypeOleinik tex.phelype at gmail.com
Fri Feb 28 16:36:27 CET 2020


Repository : https://github.com/latex3/latex3
On branch  : cs-delimited-args
Link       : https://github.com/latex3/latex3/commit/dd0062fa65d32f4974691f51d773c6949484b197

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

commit dd0062fa65d32f4974691f51d773c6949484b197
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Fri Feb 28 12:36:27 2020 -0300

    Disallow implicit begin/end-group tokens as open delimiters


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

dd0062fa65d32f4974691f51d773c6949484b197
 l3packages/xparse/xparse.dtx | 51 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 48 insertions(+), 3 deletions(-)

diff --git a/l3packages/xparse/xparse.dtx b/l3packages/xparse/xparse.dtx
index 106f94b82..d63baf5af 100644
--- a/l3packages/xparse/xparse.dtx
+++ b/l3packages/xparse/xparse.dtx
@@ -1906,7 +1906,7 @@
 \cs_new_protected:Npn \@@_normalize_type_D:w #1#2#3
   {
     \quark_if_recursion_tail_stop_do:nn {#3} { \@@_bad_arg_spec:wn }
-    \@@_single_token_check:n {#1}
+    \@@_single_token_check:n {#1} \@@_allowed_token_check:N #1
     \@@_single_token_check:n {#2}
     \@@_add_arg_spec:n { D #1 #2 {#3} }
     \tl_put_right:Nn \l_@@_last_delimiters_tl {#1}
@@ -1918,6 +1918,7 @@
     \quark_if_recursion_tail_stop_do:nn {#2} { \@@_bad_arg_spec:wn }
     \tl_if_blank:nT {#1} { \@@_bad_arg_spec:wn }
     \tl_map_function:nN {#1} \@@_single_token_check:n
+    \tl_map_function:nN {#1} \@@_allowed_token_check:N
     \@@_normalize_E_unique_check:w #1 \q_nil \q_stop
     \int_compare:nNnT { \tl_count:n {#2} } > { \tl_count:n {#1} }
       { \@@_bad_arg_spec:wn }
@@ -1946,7 +1947,7 @@
 \cs_new_protected:Npn \@@_normalize_type_t:w #1
   {
     \quark_if_recursion_tail_stop_do:Nn #1 { \@@_bad_arg_spec:wn }
-    \@@_single_token_check:n {#1}
+    \@@_single_token_check:n {#1} \@@_allowed_token_check:N #1
     \tl_put_right:Nx \l_@@_arg_spec_tl
       {
         \bool_if:NT \l_@@_obey_spaces_bool { ! }
@@ -1994,7 +1995,7 @@
 \cs_new_protected:Npn \@@_normalize_type_R:w #1#2#3
   {
     \quark_if_recursion_tail_stop_do:nn {#3} { \@@_bad_arg_spec:wn }
-    \@@_single_token_check:n {#1}
+    \@@_single_token_check:n {#1} \@@_allowed_token_check:N #1
     \@@_single_token_check:n {#2}
     \@@_delimiter_check:nnn {#1} { R/r } { \tl_to_str:n {#1} }
     \bool_set_false:N \l_@@_grab_expandably_bool
@@ -2058,6 +2059,43 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\@@_allowed_token_check:N}
+%   Some tokens are now allowed as delimiters for some argument types,
+%   notably implicit begin/end-group tokens (|\bgroup|/|\egroup|).
+%   The major problem with these tokens is that for |\peek_...| functions,
+%   a literal~|{|$_1$. is virtually indistinguishable from a |\bgroup| or
+%   other token which was |\let| to a~|{|$_1$, and the same goes
+%   for~|}|$_2$.  All other tokens can be easily distingushed from their
+%   implicit counterparts by grabbing them and looking at the string
+%   length (see \cs{@@_token_if_cs:NTF}), but for begin/end group tokens
+%   that is not possible without the risk of mistakenly grabbing the
+%   entire brace group (potentially leading to a~\texttt{!~Runaway argument}
+%   error) or trying to grab a |}|$_2$, leading to a~\texttt{!~Argument
+%   of~\dots~has an extra~|}|}.
+%    \begin{macrocode}
+\cs_new_protected:Npn \@@_allowed_token_check:N #1
+  {
+    \token_if_eq_meaning:NNTF #1 \c_group_begin_token
+        { \use:n }
+        {
+          \token_if_eq_meaning:NNTF #1 \c_group_end_token
+            { \use:n }
+            { \use_none:n }
+        }
+      {
+        \__kernel_msg_error:nnxxx
+          { xparse } { forbidden-implicit-group-token }
+          { \@@_environment_or_command: } { \tl_to_str:n {#1} }
+          {
+            \token_if_eq_meaning:NNTF #1 \c_group_begin_token
+              { begin } { end }
+          }
+        \@@_bad_def:wn
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\@@_normalize_check_gv:N, \@@_normalize_check_lu:N}
 %   Called for arguments that are always forbidden, or forbidden after
 %   an optional argument, for expandable commands.
@@ -4576,6 +4614,13 @@
     where~a~single~token~is~required,~LaTeX~found~'#2'.
     \c_@@_ignore_def_tl
   }
+\__kernel_msg_new:nnnn { xparse } { forbidden-implicit-group-token }
+  { Argument~delimiter~'#2'~for~the~#1~is~not~allowed. }
+  {
+    The~argument~specification~provided~was~not~valid:~the~implicit~
+    #3-group~token~'#2'~is~not~allowed~as~an~argument~delimiter.
+    \c_@@_ignore_def_tl
+  }
 \__kernel_msg_new:nnnn { xparse } { processor-in-expandable }
   { Argument~processor~'>{#2}'~cannot~be~used~for~the~expandable~command~'#1'. }
   {





More information about the latex3-commits mailing list.