Improve escaping text for display in Markdown.

Review Request #6653 — Created Nov. 30, 2014 and submitted

Information

Review Board
release-2.0.x
602bc68...

Reviewers

Our former approach of escaping text for use in Markdown was to define a
large regex containing patterns, and any pattern that matches was
fully escaped. This was fine for simple patterns, but it wasn't possible
to escape only a single character or set of characters in more complex
patterns.

Each pattern in the regex can now capture zero or more groups, each of
which will be individually escaped. To do this, we loop through the
groups, escaping each match and inserting that into the resulting
string. It means we do loop on each match through each possible capture
group (including those from other patterns), but it also means we no
longer have to go back through the whole string looking for and escaping
characters, just subsets. (We're really talking a ~50 microsecond
difference for a commit message with a handful of Markdown-unsafe
content anyway).

With this change, we were able to make two escaping fixes:

1. Lines starting with things like "1.2.", which are not list items,
   are no longer escaped.

2. '>' characters are no longer escaped unless they're an autolink
   (like <foo@example.com> or <http://example.com>) or a blockquote
   (single level or nested).

Unit tests pass.

Tested manually.

reviewbot
  1. Tool: Pyflakes
    Processed Files:
        reviewboard/reviews/markdown_utils.py
        reviewboard/reviews/tests.py
    
    
    
    Tool: PEP8 Style Checker
    Processed Files:
        reviewboard/reviews/markdown_utils.py
        reviewboard/reviews/tests.py
    
    
  2. 
      
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-2.0.x (4801d1f)