Skip to content

Commit

Permalink
Make sure regex patterns are raw strings (Python-Markdown#614)
Browse files Browse the repository at this point in the history
Python 3.6 is starting to reject invalid escapes.  Regular expression patterns should be raw strings to avoid having regex escapes being mistaken for invalid string escapes. Fixes Python-Markdown#611.
  • Loading branch information
facelessuser authored and waylan committed Jan 2, 2018
1 parent dd3e65a commit 2e9beae
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions markdown/extensions/smarty.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@
# Constants for quote education.
punctClass = r"""[!"#\$\%'()*+,-.\/:;<=>?\@\[\\\]\^_`{|}~]"""
endOfWordClass = r"[\s.,;:!?)]"
closeClass = "[^\ \t\r\n\[\{\(\-\u0002\u0003]"
closeClass = r"[^\ \t\r\n\[\{\(\-\u0002\u0003]"

openingQuotesBase = (
'(\s' # a whitespace char
'|&nbsp;' # or a non-breaking space entity
'|--' # or dashes
'|–|—' # or unicode
'|&[mn]dash;' # or named dash entities
'|&#8211;|&#8212;' # or decimal entities
')'
r'(\s' # a whitespace char
r'|&nbsp;' # or a non-breaking space entity
r'|--' # or dashes
r'|–|—' # or unicode
r'|&[mn]dash;' # or named dash entities
r'|&#8211;|&#8212;' # or decimal entities
r')'
)

substitutions = {
Expand Down Expand Up @@ -144,8 +144,8 @@
closingSingleQuotesRegex2 = r"(?<=%s)'(\s|s\b)" % closeClass

# All remaining quotes should be opening ones
remainingSingleQuotesRegex = "'"
remainingDoubleQuotesRegex = '"'
remainingSingleQuotesRegex = r"'"
remainingDoubleQuotesRegex = r'"'

HTML_STRICT_RE = HTML_RE + r'(?!\>)'

Expand Down
4 changes: 2 additions & 2 deletions markdown/extensions/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
def slugify(value, separator):
""" Slugify a string, to make it URL friendly. """
value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore')
value = re.sub('[^\w\s-]', '', value.decode('ascii')).strip().lower()
return re.sub('[%s\s]+' % separator, separator, value)
value = re.sub(r'[^\w\s-]', '', value.decode('ascii')).strip().lower()
return re.sub(r'[%s\s]+' % separator, separator, value)


IDCOUNT_RE = re.compile(r'^(.*)_([0-9]+)$')
Expand Down
2 changes: 1 addition & 1 deletion markdown/inlinepatterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def __init__(self, pattern, markdown_instance=None):
"""
self.pattern = pattern
self.compiled_re = re.compile("^(.*?)%s(.*)$" % pattern,
self.compiled_re = re.compile(r"^(.*?)%s(.*)$" % pattern,
re.DOTALL | re.UNICODE)

# Api for Markdown to pass safe_mode into instance
Expand Down
12 changes: 6 additions & 6 deletions markdown/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@


BLOCK_LEVEL_ELEMENTS = re.compile(
"^(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul"
"|script|noscript|form|fieldset|iframe|math"
"|hr|hr/|style|li|dt|dd|thead|tbody"
"|tr|th|td|section|footer|header|group|figure"
"|figcaption|aside|article|canvas|output"
"|progress|video|nav|main)$",
r"^(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul"
r"|script|noscript|form|fieldset|iframe|math"
r"|hr|hr/|style|li|dt|dd|thead|tbody"
r"|tr|th|td|section|footer|header|group|figure"
r"|figcaption|aside|article|canvas|output"
r"|progress|video|nav|main)$",
re.IGNORECASE
)
# Placeholders
Expand Down

0 comments on commit 2e9beae

Please sign in to comment.