[latex3-commits] [latex3/latex3] keys-groups-str: Forbid commas in l3keys groups names (and leading/trailing spaces) (c79a60f6e)
github at latex-project.org
github at latex-project.org
Thu Jan 11 23:49:36 CET 2024
Repository : https://github.com/latex3/latex3
On branch : keys-groups-str
Link : https://github.com/latex3/latex3/commit/c79a60f6eb1cc373d028d83af76d94c62b854d81
>---------------------------------------------------------------
commit c79a60f6eb1cc373d028d83af76d94c62b854d81
Author: Bruno Le Floch <blflatex at gmail.com>
Date: Thu Jan 11 23:49:36 2024 +0100
Forbid commas in l3keys groups names (and leading/trailing spaces)
Instead of treating the groups argument as a comma list and in a
second step comparing items with string comparison, we now stringify
before splitting at commas. This speeds up the code a bit at the
cost of forbidding insane group names.
>---------------------------------------------------------------
c79a60f6eb1cc373d028d83af76d94c62b854d81
l3kernel/l3keys.dtx | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/l3kernel/l3keys.dtx b/l3kernel/l3keys.dtx
index e142e6b22..bbdac54fb 100644
--- a/l3kernel/l3keys.dtx
+++ b/l3kernel/l3keys.dtx
@@ -323,9 +323,15 @@
% \begin{syntax}
% \meta{key} .groups:n = \Arg{groups}
% \end{syntax}
-% Defines \meta{key} as belonging to the \meta{groups} declared. Groups
+% Defines \meta{key} as belonging to the \meta{groups} (a
+% comma-separated list). Groups
% provide a \enquote{secondary axis} for selectively setting keys, and are
% described in Section~\ref{sec:l3keys:selective}.
+% \begin{texnote}
+% The \meta{groups} argument is turned into a string then
+% interpreted as a comma-separated list, so group names cannot
+% contain commas nor start or end with a space character.
+% \end{texnote}
% \end{function}
%
% \begin{function}[added = 2016-11-22]{.inherit:n}
@@ -2084,7 +2090,7 @@
% \begin{macrocode}
\cs_new_protected:Npn \@@_groups_set:n #1
{
- \clist_set:Nn \l_@@_groups_clist {#1}
+ \clist_set:Ne \l_@@_groups_clist { \tl_to_str:n {#1} }
\clist_if_empty:NTF \l_@@_groups_clist
{
\cs_set_eq:cN { \c_@@_groups_root_str \l_keys_path_str }
@@ -2981,7 +2987,8 @@
{ \exp_args:No \@@_set_selective:nnnn \l_@@_selective_seq }
\cs_new_protected:Npn \@@_set_selective:nnnn #1#2#3#4
{
- \seq_set_from_clist:Nn \l_@@_selective_seq {#3}
+ \exp_args:NNe \seq_set_from_clist:Nn
+ \l_@@_selective_seq { \tl_to_str:n {#3} }
\@@_set:nn {#2} {#4}
\tl_set:Nn \l_@@_selective_seq {#1}
}
@@ -3118,23 +3125,21 @@
% of groups which apply to a key with the list of those which have been
% set active. That requires two mappings, and again a different outcome
% depending on whether opt-in or opt-out is set.
-% We cannot replace the clist mapping by \cs{clist_if_in:NnTF} because
-% catcodes may not be the same; they cannot be normalized easily in the
-% clist because of the remote possibility that some items need braces
-% if they involve commas or leading/trailing spaces.
+% It is safe to use \cs{clist_if_in:NnTF} because
+% both \cs{l_@@_selective_seq} and \cs{l_@@_groups_clist} contain the
+% groups as strings, without leading/trailing spaces in any item,
+% since the \pkg{l3clist} functions were applied to the result of
+% applying \cs{tl_to_str:n}.
% \begin{macrocode}
\cs_new_protected:Npn \@@_check_groups:
{
\bool_set_false:N \l_@@_tmp_bool
\seq_map_inline:Nn \l_@@_selective_seq
{
- \clist_map_inline:Nn \l_@@_groups_clist
+ \clist_if_in:NnT \l_@@_groups_clist {##1}
{
- \str_if_eq:nnT {##1} {####1}
- {
- \bool_set_true:N \l_@@_tmp_bool
- \clist_map_break:n \seq_map_break:
- }
+ \bool_set_true:N \l_@@_tmp_bool
+ \seq_map_break:
}
}
\bool_if:NTF \l_@@_tmp_bool
More information about the latex3-commits
mailing list.