Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid escape sequences #639

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/future/backports/email/_header_value_parser.py
Expand Up @@ -659,8 +659,8 @@ def quote(self, value):
if value.token_type == 'comment':
return str(value)
return str(value).replace('\\', '\\\\').replace(
'(', '\(').replace(
')', '\)')
'(', '\\(').replace(
')', '\\)')

@property
def content(self):
Expand Down Expand Up @@ -1346,15 +1346,15 @@ def __str__(self):

_wsp_splitter = re.compile(r'([{}]+)'.format(''.join(WSP))).split
_non_atom_end_matcher = re.compile(r"[^{}]+".format(
''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\]'))).match
''.join(ATOM_ENDS).replace('\\','\\\\').replace(']','\\]'))).match
_non_printable_finder = re.compile(r"[\x00-\x20\x7F]").findall
_non_token_end_matcher = re.compile(r"[^{}]+".format(
''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\]'))).match
''.join(TOKEN_ENDS).replace('\\','\\\\').replace(']','\\]'))).match
_non_attribute_end_matcher = re.compile(r"[^{}]+".format(
''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\]'))).match
''.join(ATTRIBUTE_ENDS).replace('\\','\\\\').replace(']','\\]'))).match
_non_extended_attribute_end_matcher = re.compile(r"[^{}]+".format(
''.join(EXTENDED_ATTRIBUTE_ENDS).replace(
'\\','\\\\').replace(']','\]'))).match
'\\','\\\\').replace(']','\\]'))).match

def _validate_xtext(xtext):
"""If input token contains ASCII non-printables, register a defect."""
Expand Down Expand Up @@ -1538,7 +1538,7 @@ def get_unstructured(value):
return unstructured

def get_qp_ctext(value):
"""ctext = <printable ascii except \ ( )>
"""ctext = <printable ascii except \\ ( )>

This is not the RFC ctext, since we are handling nested comments in comment
and unquoting quoted-pairs here. We allow anything except the '()'
Expand Down Expand Up @@ -1873,7 +1873,7 @@ def get_obs_local_part(value):
return obs_local_part, value

def get_dtext(value):
""" dtext = <printable ascii except \ [ ]> / obs-dtext
""" dtext = <printable ascii except \\ [ ]> / obs-dtext
obs-dtext = obs-NO-WS-CTL / quoted-pair

We allow anything except the excluded characters, but if we find any
Expand Down
2 changes: 1 addition & 1 deletion src/future/backports/email/feedparser.py
Expand Up @@ -34,7 +34,7 @@

NLCRE = re.compile('\r\n|\r|\n')
NLCRE_bol = re.compile('(\r\n|\r|\n)')
NLCRE_eol = re.compile('(\r\n|\r|\n)\Z')
NLCRE_eol = re.compile(r'(\r\n|\r|\n)\Z')
NLCRE_crack = re.compile('(\r\n|\r|\n)')
Comment on lines 35 to 38
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These regexes look pretty broken to be honest. All of these should be raw string literals. There are probably more examples of this in the codebase.

# RFC 2822 $3.6.8 Optional fields. ftext is %d33-57 / %d59-126, Any character
# except controls, SP, and ":".
Expand Down
2 changes: 1 addition & 1 deletion src/future/backports/email/utils.py
Expand Up @@ -65,7 +65,7 @@
# How to figure out if we are processing strings that come from a byte
# source with undecodable characters.
_has_surrogates = re.compile(
'([^\ud800-\udbff]|\A)[\udc00-\udfff]([^\udc00-\udfff]|\Z)').search
r'([^\ud800-\udbff]|\A)[\udc00-\udfff]([^\udc00-\udfff]|\Z)').search

# How to deal with a string containing bytes before handing it to the
# application through the 'normal' interface.
Expand Down
4 changes: 2 additions & 2 deletions src/future/backports/html/parser.py
Expand Up @@ -28,7 +28,7 @@
starttagopen = re.compile('<[a-zA-Z]')
piclose = re.compile('>')
commentclose = re.compile(r'--\s*>')
tagfind = re.compile('([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')
tagfind = re.compile(r'([a-zA-Z][-.a-zA-Z0-9:_]*)(?:\s|/(?!>))*')
# see http://www.w3.org/TR/html5/tokenization.html#tag-open-state
# and http://www.w3.org/TR/html5/tokenization.html#tag-name-state
tagfind_tolerant = re.compile('[a-zA-Z][^\t\n\r\f />\x00]*')
Expand Down Expand Up @@ -76,7 +76,7 @@
endendtag = re.compile('>')
# the HTML 5 spec, section 8.1.2.2, doesn't allow spaces between
# </ and the tag name, so maybe this should be fixed
endtagfind = re.compile('</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')
endtagfind = re.compile(r'</\s*([a-zA-Z][-.a-zA-Z0-9:_]*)\s*>')


class HTMLParseError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion src/future/backports/http/client.py
@@ -1,4 +1,4 @@
"""HTTP/1.1 client library
r"""HTTP/1.1 client library

A backport of the Python 3.3 http/client.py module for python-future.

Expand Down
6 changes: 3 additions & 3 deletions src/future/backports/http/cookiejar.py
Expand Up @@ -209,7 +209,7 @@ def _str2time(day, mon, yr, hr, min, sec, tz):

STRICT_DATE_RE = re.compile(
r"^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) "
"(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
r"(\d\d\d\d) (\d\d):(\d\d):(\d\d) GMT$", re.ASCII)
WEEKDAY_RE = re.compile(
r"^(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)[a-z]*,?\s*", re.I | re.ASCII)
LOOSE_HTTP_DATE_RE = re.compile(
Expand Down Expand Up @@ -290,7 +290,7 @@ def http2time(text):
return _str2time(day, mon, yr, hr, min, sec, tz)

ISO_DATE_RE = re.compile(
"""^
r"""^
(\d{4}) # year
[-\/]?
(\d\d?) # numerical month
Expand Down Expand Up @@ -426,7 +426,7 @@ def split_header_words(header_values):
pairs = []
else:
# skip junk
non_junk, nr_junk_chars = re.subn("^[=\s;]*", "", text)
non_junk, nr_junk_chars = re.subn(r"^[=\s;]*", "", text)
assert nr_junk_chars > 0, (
"split_header_words bug: '%s', '%s', %s" %
(orig_text, text, pairs))
Expand Down
2 changes: 1 addition & 1 deletion src/future/backports/test/support.py
Expand Up @@ -1942,7 +1942,7 @@ def can_xattr():
os.setxattr(fp.fileno(), b"user.test", b"")
# Kernels < 2.6.39 don't respect setxattr flags.
kernel_version = platform.release()
m = re.match("2.6.(\d{1,2})", kernel_version)
m = re.match(r"2.6.(\d{1,2})", kernel_version)
can = m is None or int(m.group(1)) >= 39
except OSError:
can = False
Expand Down
2 changes: 1 addition & 1 deletion src/future/backports/urllib/parse.py
Expand Up @@ -954,7 +954,7 @@ def splitquery(url):
global _queryprog
if _queryprog is None:
import re
_queryprog = re.compile('^(.*)\?([^?]*)$')
_queryprog = re.compile(r'^(.*)\?([^?]*)$')

match = _queryprog.match(url)
if match: return match.group(1, 2)
Expand Down