Menu

#338 smartquotes: re.sub() with misplaced flags

closed-fixed
nobody
None
5
2020-03-03
2018-01-08
Jakub Wilk
No

docutils/utils/smartquotes.py contains the following statement:

text = re.sub(r"""'(?=\d{2}s)""", smart.apostrophe, text, re.UNICODE)

But the 4th argument to re.sub() is supposed to be maximum number of substitutions, not flags.

This bug was found using pydiatra.

Discussion

  • Günter Milde

    Günter Milde - 2018-01-09
    • status: open --> closed-fixed
     
  • Günter Milde

    Günter Milde - 2018-01-09

    Fixed in commit 8209.
    Thank you for the report

     
  • Jakub Wilk

    Jakub Wilk - 2018-01-13

    I forgot to mention that in Python 2.6 (which Docutils is supposed to support), re.sub() doesn't accept flags argument at all. You would have to compile the regexp beforhand, or use inline flags.

     
    • Günter Milde

      Günter Milde - 2018-01-15

      You are right, I missed this point.
      As the Unicode flag is not required in this specific expression, I removed it to restore 2.6 compatibility.
      Thank you for reporting.

       

Log in to post a comment.