A small detail on the syntax of field list markers
Arne Skjærholt <[email protected]> Sat, 5 Apr 2025 12:19:27 +0200
| Newsgroups | gmane.text.docutils.devel |
|---|---|
| Message-ID | <CALRO8FcXwOocPYN98cuZWEnR0eke2SaERF1NsYBas9n7PDi6yg@mail.gmail.com> |
While spelunking in the code, I came across the following regex
(docutils.parsers.rst.states.Body.patterns["field_marker"]) defining
the syntax of field list names and their surrounding colons:
:(?![: ])([^:\\]|\\.|:(?!([ `]|$)))*(?<! ):( +|$)
I wonder if the final lookbehind assertion might not be slightly
incorrect? The field name is not allowed to end with a space, which is
fine, but given the allowance for backslash escapes one would normally
expect ":foo\ :" to be a permitted (if odd) marker. However, given
that (?<! ) unconditionally looks for a single space before the
terminating colon it is in fact rejected, and backslashes have a
somewhat puzzling behaviour in field names.
I couldn't find any indications in docs or tests either way for what
is intended, but amending the assertion to be (?<![^\\] ) would yield
a more intuitive syntax I think.