From d241e79d078ff39d7b412d7851771d06ca1e454e Mon Sep 17 00:00:00 2001 From: Maurits van Rees Date: Wed, 9 Sep 2020 23:09:28 +0200 Subject: [PATCH] Fixed invalid escape sequences. Note that only some are for regular expressions (only one of them being reported as having an invalid escape sequence). The others are strings (well, bytes) used in a different way. It is very hard to see whether the magic mimetype changes are okay. For the first one, starting with 8BPS, for x-psd, I have found it in /usr/share/mime on Ubuntu 18.04, but even then I am not entirely sure it is correct. I could not find the others in there, but they do seem safer, as they are actually the same. For example: b'' == br'' --- Products/MimetypesRegistry/encoding.py | 8 ++++---- Products/MimetypesRegistry/mime_types/magic.py | 18 +++++++++--------- news/3130.bugfix | 2 ++ 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 news/3130.bugfix diff --git a/Products/MimetypesRegistry/encoding.py b/Products/MimetypesRegistry/encoding.py index 1de7d7a..da95771 100644 --- a/Products/MimetypesRegistry/encoding.py +++ b/Products/MimetypesRegistry/encoding.py @@ -4,10 +4,10 @@ import six -EMACS_ENCODING_RGX = re.compile('[^#]*[#\s]*-\*-\s*coding: ([^\s]*)\s*-\*-\s*') -VIM_ENCODING_RGX = re.compile('[^#]*[#\s]*vim:fileencoding=\s*([^\s]*)\s*') -XML_ENCODING_RGX = re.compile('<\?xml version=[^\s]*\s*encoding=([^\s]*)\s*\?>') # noqa -CHARSET_RGX = re.compile('charset=([^\s"]*)') +EMACS_ENCODING_RGX = re.compile(r'[^#]*[#\s]*-\*-\s*coding: ([^\s]*)\s*-\*-\s*') +VIM_ENCODING_RGX = re.compile(r'[^#]*[#\s]*vim:fileencoding=\s*([^\s]*)\s*') +XML_ENCODING_RGX = re.compile(r'<\?xml version=[^\s]*\s*encoding=([^\s]*)\s*\?>') +CHARSET_RGX = re.compile(r'charset=([^\s"]*)') def guess_encoding(buffer): diff --git a/Products/MimetypesRegistry/mime_types/magic.py b/Products/MimetypesRegistry/mime_types/magic.py index 6cb33fe..d51a617 100644 --- a/Products/MimetypesRegistry/mime_types/magic.py +++ b/Products/MimetypesRegistry/mime_types/magic.py @@ -95,7 +95,7 @@ [0, 'string', '=', - b'8BPS\ \ \000\000\000\000 &0xffffffff0000ffffffff', + br'8BPS \000\000\000\000 &0xffffffff0000ffffffff', 'image/x-psd'], [0, 'string', '=', b'#LyX', 'text/x-lyx'], [0, 'string', '=', b'DCMw', 'application/dicom'], @@ -122,12 +122,12 @@ [0, 'string', '=', - b'', + br'', 'application/x-mozilla-bookmarks'], [0, 'string', '=', - b'', + br'', 'application/x-netscape-bookmarks'], [0, 'string', @@ -137,8 +137,8 @@ [0, 'string', '=', b'', 'application/smil'], - [0, 'string', '=', b'', 'application/smil'], + [0, 'string', '=', br'', 'application/smil'], + [0, 'string', '=', br'', 'application/smil'], [0, 'string', '=', b'