[latex3-commits] [git/LaTeX3-latex3-latex2e] gh623: Ensure the macro can safely expand before calling \@if at newcommand (e7d2699d)

PhelypeOleinik phelype.oleinik at latex-project.org
Tue Jul 20 05:35:29 CEST 2021


Repository : https://github.com/latex3/latex2e
On branch  : gh623
Link       : https://github.com/latex3/latex2e/commit/e7d2699d8ae32512e29ae2a4359a39e18dfd8ca4

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

commit e7d2699d8ae32512e29ae2a4359a39e18dfd8ca4
Author: PhelypeOleinik <phelype.oleinik at latex-project.org>
Date:   Tue Jul 20 00:35:29 2021 -0300

    Ensure the macro can safely expand before calling \@if at newcommand
    
    Fixes #623


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

e7d2699d8ae32512e29ae2a4359a39e18dfd8ca4
 base/ltcmdhooks.dtx                                | 27 +++++++++++++++-------
 base/testfiles-lthooks/ltcmdhooks-012.lvt          | 18 +++++++++++++++
 .../{github-0401.tlg => ltcmdhooks-012.tlg}        |  2 ++
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/base/ltcmdhooks.dtx b/base/ltcmdhooks.dtx
index 40cd55e5..8e5afd23 100644
--- a/base/ltcmdhooks.dtx
+++ b/base/ltcmdhooks.dtx
@@ -13,8 +13,8 @@
 %
 %%% From File: ltcmdhooks.dtx
 %
-\def\ltcmdhooksversion{v1.0b}
-\def\ltcmdhooksdate{2021/05/26}
+\def\ltcmdhooksversion{v1.0c}
+\def\ltcmdhooksdate{2021/07/20}
 %
 %
 %
@@ -592,17 +592,28 @@
 %
 %   With \cs{@@_patch_DeclareRobustCommand:Nnn} we check if the command
 %   has an optional argument (with a test counter-intuitively called
-%   \tn{@if at newcommand}).  If so, we forward the action to
-%   \cs{@@_patch_newcommand:Nnn}, otherwise call the patching engine
+%   \tn{@if at newcommand}; also make sure the command doesn't take args by
+%   calling \cs{robust at command@chk at safe}).  If so, we forward the action
+%   to \cs{@@_patch_newcommand:Nnn}, otherwise call the patching engine
 %   \cs{@@_patch_expand_redefine:NNnn} with a \cs{c_false_bool} to
 %   indicate that there is no optional argument.
+%
+%   \changes{v1.0c}{2021/07/20}
+%           {Use \cs{robust at command@chk at safe} before \cs{@if at newcommand}.}
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_patch_DeclareRobustCommand:Nnn #1
   {
-    \exp_args:Nc \@if at newcommand { \cs_to_str:N #1 ~ }
-      { \exp_args:Nc \@@_patch_newcommand:Nnn }
-      { \exp_args:NNc \@@_patch_expand_redefine:NNnn \c_false_bool }
-        { \cs_to_str:N #1 ~ }
+    \exp_args:Nc \@@_patch_DeclareRobustCommand_aux:Nnn
+      { \cs_to_str:N #1 ~ }
+  }
+\cs_new_protected:Npn \@@_patch_DeclareRobustCommand_aux:Nnn #1
+  {
+    \robust at command@chk at safe #1
+      { \@if at newcommand #1 }
+      { \use_ii:nn }
+        { \@@_patch_newcommand:Nnn }
+        { \@@_patch_expand_redefine:NNnn \c_false_bool }
+          #1
   }
 %    \end{macrocode}
 % \end{macro}
diff --git a/base/testfiles-lthooks/ltcmdhooks-012.lvt b/base/testfiles-lthooks/ltcmdhooks-012.lvt
new file mode 100644
index 00000000..b7fd5227
--- /dev/null
+++ b/base/testfiles-lthooks/ltcmdhooks-012.lvt
@@ -0,0 +1,18 @@
+\RequirePackage[enable-debug,check-declarations]{expl3}
+\ExplSyntaxOn
+\debug_on:n { deprecation }
+\ExplSyntaxOff
+
+\input{regression-test}
+
+\csname __hook_cmd_begindocument_code:\endcsname
+
+\START
+
+\DeclareRobustCommand\blub[2]{{\typeout{(#1/#2)}}}
+
+\AddToHook{cmd/blub/before}[X]{\typeout{X}}
+
+\blub{1}{2}
+
+\END
diff --git a/base/testfiles-lthooks/github-0401.tlg b/base/testfiles-lthooks/ltcmdhooks-012.tlg
similarity index 92%
copy from base/testfiles-lthooks/github-0401.tlg
copy to base/testfiles-lthooks/ltcmdhooks-012.tlg
index bfbef442..1089b19e 100644
--- a/base/testfiles-lthooks/github-0401.tlg
+++ b/base/testfiles-lthooks/ltcmdhooks-012.tlg
@@ -1,2 +1,4 @@
 This is a generated file for the l3build validation system.
 Don't change this file in any respect.
+X
+(1/2)





More information about the latex3-commits mailing list.