diff --git a/base/changes.txt b/base/changes.txt index 636ce3c40..7dee04049 100644 --- a/base/changes.txt +++ b/base/changes.txt @@ -40,6 +40,11 @@ are not part of the distribution. * ltfilehook.dtx: document include/excluded hooks +2022-03-18 Phelype Oleinik + + * ltcmd.dtx (subsection{Utilities}): + Fix \@@_cmd_type_cases:NnnnnF prematurely expanding macros (gh/795). + 2022-03-18 Joseph Wright * ltkeys.dtx: diff --git a/base/doc/ltnews35.tex b/base/doc/ltnews35.tex index c46540d07..3edfd91d2 100644 --- a/base/doc/ltnews35.tex +++ b/base/doc/ltnews35.tex @@ -684,6 +684,16 @@ \subsection{Make \cs{cite}\texttt{\textbraceleft\textbraceright} produce a warni +\subsection{Fix adding \hook{cmd} hooks to simple macros} + +A bug in how \LaTeX{} would detect the type of a command was causing a +premature forced expansion of such commands, which, depending on their +definition, could be harmless or could cause severe trouble. This has +been fixed in the latest release. +% +\githubissue{795} +\sxissue{q/637565} + \section{Changes to packages in the \pkg{amsmath} category} diff --git a/base/ltcmd.dtx b/base/ltcmd.dtx index f52b32479..59aa5bf47 100644 --- a/base/ltcmd.dtx +++ b/base/ltcmd.dtx @@ -34,8 +34,8 @@ %%% From File: ltcmd.dtx % % \begin{macrocode} -\def\ltcmdversion{v1.0k} -\def\ltcmddate{2022-02-28} +\def\ltcmdversion{v1.0l} +\def\ltcmddate{2022-03-18} % \end{macrocode} % %<*driver> @@ -4097,8 +4097,10 @@ % \begin{macro}{\@@_cmd_type_cases:Nnnnn} % \changes{v1.0d}{2021/04/19}{Renamed \cs{__cmd_cmd_if_xparse:NTF} to % \cs{__kernel_cmd_if_xparse:NTF} for cross-module usage} -% \changes{v1.0d}{2021/07/30}{Added \cs{@@_cmd_type_cases:Nnnnn} for +% \changes{v1.0d}{2021/07/30}{Added \cs{@@_cmd_type_cases:NnnnnF} for % \cs{NewCommandCopy} and \cs{ShowCommand} support} +% \changes{v1.0l}{2022/03/18}{Fix \cs{@@_cmd_type_cases:NnnnnF} +%" prematurely expanding macros (gh/795)} % \begin{macro}{\@@_cmd_if_xparse_aux:N} % % To determine whether the command is an \pkg{xparse} command check @@ -4117,22 +4119,14 @@ \exp_args:Ne \str_case_e:nnF { \exp_args:Nf \tl_if_empty:nT { \cs_argument_spec:N #1 } - { - \token_if_macro:NT #1 - { - \exp_after:wN \exp_after:wN - \exp_after:wN \token_to_str:N - \exp_after:wN \use_i_delimit_by_q_stop:nw - #1 \scan_stop: \q_stop - } - } + { \exp_not:N \exp_not:n { \exp_not:e { \tl_head:N #1 } } } } { - { \token_to_str:N \@@_start:nNNnnn } {#2} - { \token_to_str:N \@@_start_expandable:nNNNNn } {#3} - { \token_to_str:N \@@_start_env:nnnnn } {#4} + { \exp_not:N \@@_start:nNNnnn } {#2} + { \exp_not:N \@@_start_expandable:nNNNNn } {#3} + { \exp_not:N \@@_start_env:nnnnn } {#4} { - \exp_after:wN \token_to_str:N + \exp_after:wN \exp_not:N \cs:w environment~ \exp_last_unbraced:Ne \use_none:nnn { \cs_to_str:N #1 } ~end~aux \cs_end: diff --git a/base/testfiles/github-0795.lvt b/base/testfiles/github-0795.lvt new file mode 100644 index 000000000..ea823a972 --- /dev/null +++ b/base/testfiles/github-0795.lvt @@ -0,0 +1,12 @@ +\input test2e +\START +\def\test{\typeout{test}\fi} +\def\testx{{\typeout{test x}\fi}} +\AddToHook{cmd/test/after}{\typeout{hello}} +\AddToHook{cmd/testx/after}{\typeout{hello x}} +\@kernel@after@begindocument +\if11 % \fi comes from \test +\test +\if11 % \fi comes from \testx +\testx +\END diff --git a/base/testfiles/github-0795.tlg b/base/testfiles/github-0795.tlg new file mode 100644 index 000000000..8b4753350 --- /dev/null +++ b/base/testfiles/github-0795.tlg @@ -0,0 +1,6 @@ +This is a generated file for the LaTeX2e validation system. +Don't change this file in any respect. +test +hello +test x +hello x