[latex3-commits] [git/LaTeX3-latex3-latex2e] keyval-detect: Protect against non-standard catcodes (51f91aba)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Aug 31 08:27:16 CEST 2022
Repository : https://github.com/latex3/latex2e
On branch : keyval-detect
Link : https://github.com/latex3/latex2e/commit/51f91aba8eb7e96a8fd1b362cf43176207ec91ed
>---------------------------------------------------------------
commit 51f91aba8eb7e96a8fd1b362cf43176207ec91ed
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Mon Aug 29 11:40:50 2022 +0200
Protect against non-standard catcodes
>---------------------------------------------------------------
51f91aba8eb7e96a8fd1b362cf43176207ec91ed
base/ltcmd.dtx | 22 ++++++++++++++++------
base/testfiles-ltcmd/ltcmd008.lvt | 12 ++++++++++++
base/testfiles-ltcmd/ltcmd008.tlg | 6 ++++++
3 files changed, 34 insertions(+), 6 deletions(-)
diff --git a/base/ltcmd.dtx b/base/ltcmd.dtx
index 1776d11a..a823e8dd 100644
--- a/base/ltcmd.dtx
+++ b/base/ltcmd.dtx
@@ -3962,6 +3962,7 @@
%
% \begin{macro}{\@@_arg_to_keyvalue:nn}
% \changes{v1.1a}{2022/08/10}{New internal arg-to-keyval processor}
+% \begin{macro}{\@@_arg_to_keyvalue_braces:nn}
% \begin{macro}{\@@_arg_to_keyvalue_auxi:nnn}
% \begin{macro}{\@@_arg_to_keyvalue_auxii:nnNw}
% \begin{macro}{\@@_arg_to_keyvalue_auxiii:nnn}
@@ -3982,14 +3983,22 @@
% series of steps rather than a delimited argument.
% \begin{macrocode}
\cs_new_protected:Npn \@@_arg_to_keyvalue:nn #1#2
+ { \tl_trim_spaces_apply:nN {#2} \@@_arg_to_keyvalue_braces:nn {#1} }
+\cs_new_protected:Npn \@@_arg_to_keyvalue_braces:nn #1#2
{
- \str_if_eq:eeTF
- { \exp_not:n {#2} }
- { { \exp_not:o { \use:n #2 } } }
- { \tl_set:Nn \ProcessedArgument { #1 = #2 } }
+ \tl_if_head_is_group:nT {#1}
{
- \tl_trim_spaces_apply:nN {#2} \@@_arg_to_keyvalue_auxi:nnn
- {#1} {#2}
+ \tl_if_blank:oT { \use_none:n #1 }
+ {
+ \tl_set:Nx \ProcessedArgument
+ { #2 = { \exp_not:o { \use:n #1 } } }
+ \use_none:nn
+ }
+ }
+ \use:n
+ {
+ \tl_trim_spaces_apply:nN {#1} \@@_arg_to_keyvalue_auxi:nnn
+ {#2} {#1}
}
}
\cs_new_protected:Npn \@@_arg_to_keyvalue_auxi:nnn #1#2#3
@@ -4115,6 +4124,7 @@
% \end{macro}
% \end{macro}
% \end{macro}
+% \end{macro}
%
% \subsection{Access to the argument specification}
%
diff --git a/base/testfiles-ltcmd/ltcmd008.lvt b/base/testfiles-ltcmd/ltcmd008.lvt
index b0fbb846..40f2f49d 100644
--- a/base/testfiles-ltcmd/ltcmd008.lvt
+++ b/base/testfiles-ltcmd/ltcmd008.lvt
@@ -38,4 +38,16 @@
\foo { bong = bing }
}
+\TEST { Awkward~catcodes }
+ {
+ \DeclareDocumentCommand \foo { = { TOC-entry } m }
+ { \TYPE { \detokenize { (#1) } } }
+ \foo { { baz } }
+ \catcode`\[=1
+ \catcode`\]=2
+ \tl_rescan:nn
+ { \char_set_catcode_group_begin:N \[ \char_set_catcode_group_end:N \] }
+ { \foo [ [ baz ] ] }
+ }
+
\END
\ No newline at end of file
diff --git a/base/testfiles-ltcmd/ltcmd008.tlg b/base/testfiles-ltcmd/ltcmd008.tlg
index a5249174..9d78036a 100644
--- a/base/testfiles-ltcmd/ltcmd008.tlg
+++ b/base/testfiles-ltcmd/ltcmd008.tlg
@@ -25,3 +25,9 @@ TEST 3: Mixed argument types using ={...}
(TOC-entry={baz})
(TOC-entry={bong=bing})
============================================================
+============================================================
+TEST 4: Awkward catcodes
+============================================================
+(TOC-entry={baz})
+(TOC-entry={baz})
+============================================================
More information about the latex3-commits
mailing list.