Skip to content

Commit

Permalink
Make keyval_parse alignment safe (fixes #896)
Browse files Browse the repository at this point in the history
  • Loading branch information
blefloch committed May 10, 2021
1 parent 73e9610 commit feea789
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
1 change: 1 addition & 0 deletions l3kernel/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ this project uses date-based 'snapshot' version identifiers.

### Fixed
- Loading of backend in generic DVI mode (issue #905)
- Make `\keyval_parse:nnn` alignment-safe (issue #896)

### Changed
- Speed up \group_align_safe_begin: (pull #906)
Expand Down
15 changes: 11 additions & 4 deletions l3kernel/l3keys.dtx
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@
% \end{verbatim}
% are treated identically.
%
% \begin{function}[rEXP, added=2020-12-19]{\keyval_parse:nnn}
% \begin{function}[rEXP, added=2020-12-19, updated = 2021-05-10]{\keyval_parse:nnn}
% \begin{syntax}
% \cs{keyval_parse:nnn} \Arg{code_1} \Arg{code_2} \Arg{key--value list}
% \end{syntax}
Expand Down Expand Up @@ -929,7 +929,7 @@
% \end{texnote}
% \end{function}
%
% \begin{function}[rEXP,updated = 2020-12-19]{\keyval_parse:NNn}
% \begin{function}[rEXP, updated = 2021-05-10]{\keyval_parse:NNn}
% \begin{syntax}
% \cs{keyval_parse:NNn} \meta{function_1} \meta{function_2} \Arg{key--value list}
% \end{syntax}
Expand Down Expand Up @@ -1017,7 +1017,10 @@
% argument.
% \begin{macrocode}
\cs_new:Npn \keyval_parse:nnn ##1 ##2 ##3
{ \@@_loop_active:nnw {##1} {##2} \s_@@_mark ##3 #1 \s_@@_tail #1 }
{
\group_align_safe_begin:
\@@_loop_active:nnw {##1} {##2} \s_@@_mark ##3 #1 \s_@@_tail #1
}
\cs_new_eq:NN \keyval_parse:NNn \keyval_parse:nnn
% \end{macrocode}
% \end{macro}
Expand Down Expand Up @@ -1255,7 +1258,7 @@
\cs_new:Npn \@@_end_loop_active:w
\s_@@_tail
\@@_loop_other:nnw ##1 \s_@@_mark \s_@@_tail , \s_@@_tail ,
{ }
{ \group_align_safe_end: }
% \end{macrocode}
% \end{macro}
%
Expand All @@ -1280,14 +1283,18 @@
{
\@@_if_blank:w \s_@@_mark #2 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
\s_@@_mark \s_@@_stop
\group_align_safe_end:
\exp_not:n { #4 { #2 } { #1 } }
\group_align_safe_begin:
\@@_loop_other:nnw {#3} {#4}
}
\cs_new:Npn \@@_key:nn #1 #2
{
\@@_if_blank:w \s_@@_mark #1 \s_@@_nil \s_@@_stop \@@_blank_key_error:w
\s_@@_mark \s_@@_stop
\group_align_safe_end:
\exp_not:n { #2 { #1 } }
\group_align_safe_begin:
\@@_loop_other:nnw {#2}
}
% \end{macrocode}
Expand Down
40 changes: 40 additions & 0 deletions l3kernel/testfiles/m3keyval004.lvt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
\documentclass{minimal}
\input{regression-test}
\RequirePackage[enable-debug]{expl3}
\ExplSyntaxOn
\debug_on:n { check-declarations , deprecation , log-functions }
\ExplSyntaxOff
\begin{document}
\START
\AUTHOR{Bruno Le Floch}
\ExplSyntaxOn

\OMIT
\cs_new:Npn \test:nn #1#2
{
\TEST { while~ searching~ for~ noalign/omit }
{
\tex_halign:D
{
\TYPE{0} ## \TYPE{1} \tex_cr:D
\keyval_parse:nnn {#1} {#2} { a, a=b&c }
\tex_cr:D
}
}
\TEST { with~ relax }
{
\tex_halign:D
{
\TYPE{0} ## \TYPE{1} \tex_cr:D
\scan_stop: \keyval_parse:nnn {#1} {#2} { a, a=b&c }
\tex_cr:D
}
}
}
\TIMO

\test:nn \use_none:n \use_none:nn
\test:nn { \scan_stop: \use_none:n } { \scan_stop: \use_none:nn }


\END
27 changes: 27 additions & 0 deletions l3kernel/testfiles/m3keyval004.tlg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
This is a generated file for the LaTeX (2e + expl3) validation system.
Don't change this file in any respect.
Author: Bruno Le Floch
============================================================
TEST 1: while searching for noalign/omit
============================================================
0
1
============================================================
============================================================
TEST 2: with relax
============================================================
0
1
============================================================
============================================================
TEST 3: while searching for noalign/omit
============================================================
0
1
============================================================
============================================================
TEST 4: with relax
============================================================
0
1
============================================================

0 comments on commit feea789

Please sign in to comment.