Avoid crash when a known command's required arg ends a group#190
Conversation
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
|
This does not seem to fully fix it: |
|
Thanks for testing. The two cases differ because \label has a known one-required-argument signature while \i does not, so only \label reaches the required-arg path. This PR stops that path from consuming the closing brace (the TypeError in #189), which is why {\label} no longer crashes. Your \foreach \label in {...} example is a separate issue: with no brace group present, the required-arg fallback (rule c in read_arg_required) takes the next token, here the text ' in ', as the argument. That is the documented behaviour for a missing brace arg, so declining to consume a bare text token would be a behaviour change beyond the crash fix. Happy to extend the PR to skip text tokens in that fallback for known commands if that is the direction you'd prefer. |
Summary
TexSoup(r"{\label}")raisedTypeError: Malformed argumentbecause\labelhas a known one-required-argument signature, and when its argument is absent at the end of a group the parser consumed the closing}as the argument, leaving the group unterminated.read_arg_requirednow skips the fallback "use the next token as the argument" branch when that next token is a closing delimiter (}or]), so a missing required argument is simply left empty instead of swallowing the delimiter.The reduced case is
{\label}, but the same crash hit the original\tikzmath{\label = 1;}/\node[...] {\label}document in the issue.Validation
python3 -m pytest(190 passed)test_known_command_missing_arg_at_group_endfails on the current parser and passes with this change.